Deadlock patch for kmod

Richard Gooch (rgooch@workaholix.atnf.CSIRO.AU)
Thu, 23 Apr 1998 11:34:10 +1000


Hi, Linus. Below is a small patch that should fix a nasty deadlock
with kmod: if a modprobe initiated by kmod does something that
triggers another module load request via kmod, we have a deadlock. I
hope I've got the process killing semantics correct.

Regards,

Richard....

--- kmod.c~ Tue Apr 14 11:11:38 1998
+++ kmod.c Thu Apr 23 11:32:15 1998
@@ -25,6 +25,7 @@
*/
static struct wait_queue * kmod_queue = NULL;
static struct timer_list kmod_unload_timer;
+static pid_t modprobe_pid = 0;

/*
It is not easy to implement a full fork in kernel-space on some
@@ -75,8 +76,10 @@
} else {
pid = kernel_thread(kmod_exec_modprobe, NULL, SIGCHLD);
if (pid > 0) {
+ modprobe_pid = pid;
waitpid(pid, NULL, 0);
module_name[0] = '\0';
+ modprobe_pid = 0;
wake_up(&kmod_queue);
} else {
printk(KERN_ERR "kmod: fork failed, errno %d\n", -pid);
@@ -131,6 +134,15 @@
*/
int request_module(const char * name)
{
+ /* sanity check: am I modprobe called by kmod? */
+ if (current->pid == modprobe_pid) {
+ /* deadlock! */
+ printk ("request_module(%d): kmod:modprobe tried to load \"%s\"\n",
+ (int) current->pid, name);
+ kill_proc (current->pid, SIGKILL, 1);
+ return -EBUSY;
+ }
+
/* first, copy the name of the module into module_name */
/* then wake_up() the kmod daemon */
/* wait for the kmod daemon to finish (it will wake us up) */

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu