[PATCH] uml: mconsole locking
authorJeff Dike <jdike@addtoit.com>
Sat, 10 Feb 2007 09:44:01 +0000 (01:44 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Sun, 11 Feb 2007 18:51:21 +0000 (10:51 -0800)
Locking fixes.  Locking was totally lacking for the mconsole_devices, which
got a spin lock, and the unplugged pages data, which got a mutex.

The locking of the mconsole console output code was confused.  Now, the
console_lock (renamed to client_lock) protects the clients list.

Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/um/drivers/mconsole_kern.c
arch/um/drivers/net_kern.c
arch/um/drivers/ssl.c
arch/um/drivers/ubd_kern.c
arch/um/kernel/tt/gdb_kern.c

index 832d5c766ca88b717623a83b855882fcf646b0df..b4dbd102da0ee779cfbbe42c5f87a28872622f2e 100644 (file)
@@ -337,13 +337,15 @@ void mconsole_stop(struct mc_request *req)
        mconsole_reply(req, "", 0, 0);
 }
 
-/* This list is populated by __initcall routines. */
-
+static DEFINE_SPINLOCK(mc_devices_lock);
 static LIST_HEAD(mconsole_devices);
 
 void mconsole_register_dev(struct mc_device *new)
 {
+       spin_lock(&mc_devices_lock);
+       BUG_ON(!list_empty(&new->list));
        list_add(&new->list, &mconsole_devices);
+       spin_unlock(&mc_devices_lock);
 }
 
 static struct mc_device *mconsole_find_dev(char *name)
@@ -367,6 +369,7 @@ struct unplugged_pages {
        void *pages[UNPLUGGED_PER_PAGE];
 };
 
+static DECLARE_MUTEX(plug_mem_mutex);
 static unsigned long long unplugged_pages_count = 0;
 static struct list_head unplugged_pages = LIST_HEAD_INIT(unplugged_pages);
 static int unplug_index = UNPLUGGED_PER_PAGE;
@@ -402,6 +405,7 @@ static int mem_config(char *str, char **error_out)
 
        diff /= PAGE_SIZE;
 
+       down(&plug_mem_mutex);
        for(i = 0; i < diff; i++){
                struct unplugged_pages *unplugged;
                void *addr;
@@ -447,7 +451,7 @@ static int mem_config(char *str, char **error_out)
                                        printk("Failed to release memory - "
                                               "errno = %d\n", err);
                                        *error_out = "Failed to release memory";
-                                       goto out;
+                                       goto out_unlock;
                                }
                                unplugged->pages[unplug_index++] = addr;
                        }
@@ -457,6 +461,8 @@ static int mem_config(char *str, char **error_out)
        }
 
        err = 0;
+out_unlock:
+       up(&plug_mem_mutex);
 out:
        return err;
 }
@@ -487,6 +493,7 @@ static int mem_remove(int n, char **error_out)
 }
 
 static struct mc_device mem_mc = {
+       .list           = LIST_HEAD_INIT(mem_mc.list),
        .name           = "mem",
        .config         = mem_config,
        .get_config     = mem_get_config,
@@ -629,7 +636,7 @@ struct mconsole_output {
        struct mc_request *req;
 };
 
-static DEFINE_SPINLOCK(console_lock);
+static DEFINE_SPINLOCK(client_lock);
 static LIST_HEAD(clients);
 static char console_buf[MCONSOLE_MAX_DATA];
 static int console_index = 0;
@@ -684,16 +691,18 @@ static void with_console(struct mc_request *req, void (*proc)(void *),
        unsigned long flags;
 
        entry.req = req;
+       spin_lock_irqsave(&client_lock, flags);
        list_add(&entry.list, &clients);
-       spin_lock_irqsave(&console_lock, flags);
+       spin_unlock_irqrestore(&client_lock, flags);
 
        (*proc)(arg);
 
        mconsole_reply_len(req, console_buf, console_index, 0, 0);
        console_index = 0;
 
-       spin_unlock_irqrestore(&console_lock, flags);
+       spin_lock_irqsave(&client_lock, flags);
        list_del(&entry.list);
+       spin_unlock_irqrestore(&client_lock, flags);
 }
 
 #ifdef CONFIG_MAGIC_SYSRQ
index eede892a4f38d5a44719af2fefdb29e315a473df..c1838645ae28b54ce7f7f3e020ce62eaeba27cdf 100644 (file)
@@ -690,6 +690,7 @@ static int net_remove(int n, char **error_out)
 }
 
 static struct mc_device net_mc = {
+       .list           = LIST_HEAD_INIT(net_mc.list),
        .name           = "eth",
        .config         = net_config,
        .get_config     = NULL,
index 1e82430b8444217d1bbdeb3845ff2d36c697825d..fe400acc97515794bca75da605aecdd42f76c000 100644 (file)
@@ -64,6 +64,7 @@ static struct line_driver driver = {
        .symlink_from           = "serial",
        .symlink_to             = "tts",
        .mc  = {
+               .list           = LIST_HEAD_INIT(driver.mc.list),
                .name           = "ssl",
                .config         = ssl_config,
                .get_config     = ssl_get_config,
index f4db97efc014d9ddbc214c6ed0d6f736462b6870..c1d40fb738e6b55b666baac46803a8a8df1934a5 100644 (file)
@@ -828,6 +828,7 @@ out:
  * ubd-specific locks.
  */
 static struct mc_device ubd_mc = {
+       .list           = LIST_HEAD_INIT(ubd_mc.list),
        .name           = "ubd",
        .config         = ubd_config,
        .get_config     = ubd_get_config,
index a1af96ef9ee26664ef64e160e337694406def9d9..03b06bc00771596d55856641de8963ebb9c16e8c 100644 (file)
@@ -12,6 +12,7 @@ extern int gdb_config(char *str, char **error_out);
 extern int gdb_remove(int n, char **error_out);
 
 static struct mc_device gdb_mc = {
+       .list           = INIT_LIST_HEAD(gdb_mc.list),
        .name           = "gdb",
        .config         = gdb_config,
        .remove         = gdb_remove,