Skip to content

Commit b639e86

Browse files
fweisbectorvalds
authored andcommitted
kmod: add up-to-date explanations on the purpose of each asynchronous levels
There seem to be quite some confusions on the comments, likely due to changes that came after them. Now since it's very non obvious why we have 3 levels of asynchronous code to implement usermodehelpers, it's important to comment in detail the reason of this layout. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Rik van Riel <riel@redhat.com> Reviewed-by: Oleg Nesterov <oleg@redhat.com> Cc: Christoph Lameter <cl@linux.com> Cc: Tejun Heo <tj@kernel.org> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d097c02 commit b639e86

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

‎kernel/kmod.c‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ static int call_usermodehelper_exec_async(void *data)
225225
spin_unlock_irq(&current->sighand->siglock);
226226

227227
/*
228-
* Our parent is keventd, which runs with elevated scheduling priority.
229-
* Avoid propagating that into the userspace child.
228+
* Our parent is khelper which runs with elevated scheduling
229+
* priority. Avoid propagating that into the userspace child.
230230
*/
231231
set_user_nice(current, 0);
232232

@@ -267,7 +267,11 @@ static int call_usermodehelper_exec_async(void *data)
267267
do_exit(0);
268268
}
269269

270-
/* Keventd can't block, but this (a child) can. */
270+
/*
271+
* Handles UMH_WAIT_PROC. Our parent khelper can't wait for usermodehelper
272+
* completion without blocking every other pending requests. That's why
273+
* we use a kernel thread dedicated for that purpose.
274+
*/
271275
static int call_usermodehelper_exec_sync(void *data)
272276
{
273277
struct subprocess_info *sub_info = data;
@@ -283,8 +287,8 @@ static int call_usermodehelper_exec_sync(void *data)
283287
/*
284288
* Normally it is bogus to call wait4() from in-kernel because
285289
* wait4() wants to write the exit code to a userspace address.
286-
* But call_usermodehelper_exec_sync() always runs as keventd,
287-
* and put_user() to a kernel address works OK for kernel
290+
* But call_usermodehelper_exec_sync() always runs as kernel
291+
* thread and put_user() to a kernel address works OK for kernel
288292
* threads, due to their having an mm_segment_t which spans the
289293
* entire address space.
290294
*
@@ -305,7 +309,19 @@ static int call_usermodehelper_exec_sync(void *data)
305309
do_exit(0);
306310
}
307311

308-
/* This is run by khelper thread */
312+
/*
313+
* This function doesn't strictly needs to be called asynchronously. But we
314+
* need to create the usermodehelper kernel threads from a task that is affine
315+
* to all CPUs (or nohz housekeeping ones) such that they inherit a widest
316+
* affinity irrespective of call_usermodehelper() callers with possibly reduced
317+
* affinity (eg: per-cpu workqueues). We don't want usermodehelper targets to
318+
* contend any busy CPU.
319+
* Khelper provides such wide affinity.
320+
*
321+
* Besides, khelper provides the privilege level that caller might not have to
322+
* perform the usermodehelper request.
323+
*
324+
*/
309325
static void call_usermodehelper_exec_work(struct work_struct *work)
310326
{
311327
struct subprocess_info *sub_info =
@@ -533,8 +549,8 @@ EXPORT_SYMBOL(call_usermodehelper_setup);
533549
* from interrupt context.
534550
*
535551
* Runs a user-space application. The application is started
536-
* asynchronously if wait is not set, and runs as a child of keventd.
537-
* (ie. it runs with full root capabilities).
552+
* asynchronously if wait is not set, and runs as a child of khelper.
553+
* (ie. it runs with full root capabilities and wide affinity).
538554
*/
539555
int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
540556
{

0 commit comments

Comments
 (0)