diff options
author | Jeff Dike <jdike@addtoit.com> | 2007-02-10 04:44:01 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-02-11 13:51:21 -0500 |
commit | 84f48d4f2b511db15fda67fd38462b91abd0af53 (patch) | |
tree | 7de15447387c3ace3dfda3b4dabc0b6d3dd1c643 /arch/um | |
parent | d471c0fca7eae1ffd4f7d4c11ee835ff70aaa71f (diff) |
[PATCH] uml: mconsole locking
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>
Diffstat (limited to 'arch/um')
-rw-r--r-- | arch/um/drivers/mconsole_kern.c | 21 | ||||
-rw-r--r-- | arch/um/drivers/net_kern.c | 1 | ||||
-rw-r--r-- | arch/um/drivers/ssl.c | 1 | ||||
-rw-r--r-- | arch/um/drivers/ubd_kern.c | 1 | ||||
-rw-r--r-- | arch/um/kernel/tt/gdb_kern.c | 1 |
5 files changed, 19 insertions, 6 deletions
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c index 832d5c766ca8..b4dbd102da0e 100644 --- a/arch/um/drivers/mconsole_kern.c +++ b/arch/um/drivers/mconsole_kern.c | |||
@@ -337,13 +337,15 @@ void mconsole_stop(struct mc_request *req) | |||
337 | mconsole_reply(req, "", 0, 0); | 337 | mconsole_reply(req, "", 0, 0); |
338 | } | 338 | } |
339 | 339 | ||
340 | /* This list is populated by __initcall routines. */ | 340 | static DEFINE_SPINLOCK(mc_devices_lock); |
341 | |||
342 | static LIST_HEAD(mconsole_devices); | 341 | static LIST_HEAD(mconsole_devices); |
343 | 342 | ||
344 | void mconsole_register_dev(struct mc_device *new) | 343 | void mconsole_register_dev(struct mc_device *new) |
345 | { | 344 | { |
345 | spin_lock(&mc_devices_lock); | ||
346 | BUG_ON(!list_empty(&new->list)); | ||
346 | list_add(&new->list, &mconsole_devices); | 347 | list_add(&new->list, &mconsole_devices); |
348 | spin_unlock(&mc_devices_lock); | ||
347 | } | 349 | } |
348 | 350 | ||
349 | static struct mc_device *mconsole_find_dev(char *name) | 351 | static struct mc_device *mconsole_find_dev(char *name) |
@@ -367,6 +369,7 @@ struct unplugged_pages { | |||
367 | void *pages[UNPLUGGED_PER_PAGE]; | 369 | void *pages[UNPLUGGED_PER_PAGE]; |
368 | }; | 370 | }; |
369 | 371 | ||
372 | static DECLARE_MUTEX(plug_mem_mutex); | ||
370 | static unsigned long long unplugged_pages_count = 0; | 373 | static unsigned long long unplugged_pages_count = 0; |
371 | static struct list_head unplugged_pages = LIST_HEAD_INIT(unplugged_pages); | 374 | static struct list_head unplugged_pages = LIST_HEAD_INIT(unplugged_pages); |
372 | static int unplug_index = UNPLUGGED_PER_PAGE; | 375 | static int unplug_index = UNPLUGGED_PER_PAGE; |
@@ -402,6 +405,7 @@ static int mem_config(char *str, char **error_out) | |||
402 | 405 | ||
403 | diff /= PAGE_SIZE; | 406 | diff /= PAGE_SIZE; |
404 | 407 | ||
408 | down(&plug_mem_mutex); | ||
405 | for(i = 0; i < diff; i++){ | 409 | for(i = 0; i < diff; i++){ |
406 | struct unplugged_pages *unplugged; | 410 | struct unplugged_pages *unplugged; |
407 | void *addr; | 411 | void *addr; |
@@ -447,7 +451,7 @@ static int mem_config(char *str, char **error_out) | |||
447 | printk("Failed to release memory - " | 451 | printk("Failed to release memory - " |
448 | "errno = %d\n", err); | 452 | "errno = %d\n", err); |
449 | *error_out = "Failed to release memory"; | 453 | *error_out = "Failed to release memory"; |
450 | goto out; | 454 | goto out_unlock; |
451 | } | 455 | } |
452 | unplugged->pages[unplug_index++] = addr; | 456 | unplugged->pages[unplug_index++] = addr; |
453 | } | 457 | } |
@@ -457,6 +461,8 @@ static int mem_config(char *str, char **error_out) | |||
457 | } | 461 | } |
458 | 462 | ||
459 | err = 0; | 463 | err = 0; |
464 | out_unlock: | ||
465 | up(&plug_mem_mutex); | ||
460 | out: | 466 | out: |
461 | return err; | 467 | return err; |
462 | } | 468 | } |
@@ -487,6 +493,7 @@ static int mem_remove(int n, char **error_out) | |||
487 | } | 493 | } |
488 | 494 | ||
489 | static struct mc_device mem_mc = { | 495 | static struct mc_device mem_mc = { |
496 | .list = LIST_HEAD_INIT(mem_mc.list), | ||
490 | .name = "mem", | 497 | .name = "mem", |
491 | .config = mem_config, | 498 | .config = mem_config, |
492 | .get_config = mem_get_config, | 499 | .get_config = mem_get_config, |
@@ -629,7 +636,7 @@ struct mconsole_output { | |||
629 | struct mc_request *req; | 636 | struct mc_request *req; |
630 | }; | 637 | }; |
631 | 638 | ||
632 | static DEFINE_SPINLOCK(console_lock); | 639 | static DEFINE_SPINLOCK(client_lock); |
633 | static LIST_HEAD(clients); | 640 | static LIST_HEAD(clients); |
634 | static char console_buf[MCONSOLE_MAX_DATA]; | 641 | static char console_buf[MCONSOLE_MAX_DATA]; |
635 | static int console_index = 0; | 642 | static int console_index = 0; |
@@ -684,16 +691,18 @@ static void with_console(struct mc_request *req, void (*proc)(void *), | |||
684 | unsigned long flags; | 691 | unsigned long flags; |
685 | 692 | ||
686 | entry.req = req; | 693 | entry.req = req; |
694 | spin_lock_irqsave(&client_lock, flags); | ||
687 | list_add(&entry.list, &clients); | 695 | list_add(&entry.list, &clients); |
688 | spin_lock_irqsave(&console_lock, flags); | 696 | spin_unlock_irqrestore(&client_lock, flags); |
689 | 697 | ||
690 | (*proc)(arg); | 698 | (*proc)(arg); |
691 | 699 | ||
692 | mconsole_reply_len(req, console_buf, console_index, 0, 0); | 700 | mconsole_reply_len(req, console_buf, console_index, 0, 0); |
693 | console_index = 0; | 701 | console_index = 0; |
694 | 702 | ||
695 | spin_unlock_irqrestore(&console_lock, flags); | 703 | spin_lock_irqsave(&client_lock, flags); |
696 | list_del(&entry.list); | 704 | list_del(&entry.list); |
705 | spin_unlock_irqrestore(&client_lock, flags); | ||
697 | } | 706 | } |
698 | 707 | ||
699 | #ifdef CONFIG_MAGIC_SYSRQ | 708 | #ifdef CONFIG_MAGIC_SYSRQ |
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c index eede892a4f38..c1838645ae28 100644 --- a/arch/um/drivers/net_kern.c +++ b/arch/um/drivers/net_kern.c | |||
@@ -690,6 +690,7 @@ static int net_remove(int n, char **error_out) | |||
690 | } | 690 | } |
691 | 691 | ||
692 | static struct mc_device net_mc = { | 692 | static struct mc_device net_mc = { |
693 | .list = LIST_HEAD_INIT(net_mc.list), | ||
693 | .name = "eth", | 694 | .name = "eth", |
694 | .config = net_config, | 695 | .config = net_config, |
695 | .get_config = NULL, | 696 | .get_config = NULL, |
diff --git a/arch/um/drivers/ssl.c b/arch/um/drivers/ssl.c index 1e82430b8444..fe400acc9751 100644 --- a/arch/um/drivers/ssl.c +++ b/arch/um/drivers/ssl.c | |||
@@ -64,6 +64,7 @@ static struct line_driver driver = { | |||
64 | .symlink_from = "serial", | 64 | .symlink_from = "serial", |
65 | .symlink_to = "tts", | 65 | .symlink_to = "tts", |
66 | .mc = { | 66 | .mc = { |
67 | .list = LIST_HEAD_INIT(driver.mc.list), | ||
67 | .name = "ssl", | 68 | .name = "ssl", |
68 | .config = ssl_config, | 69 | .config = ssl_config, |
69 | .get_config = ssl_get_config, | 70 | .get_config = ssl_get_config, |
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index f4db97efc014..c1d40fb738e6 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c | |||
@@ -828,6 +828,7 @@ out: | |||
828 | * ubd-specific locks. | 828 | * ubd-specific locks. |
829 | */ | 829 | */ |
830 | static struct mc_device ubd_mc = { | 830 | static struct mc_device ubd_mc = { |
831 | .list = LIST_HEAD_INIT(ubd_mc.list), | ||
831 | .name = "ubd", | 832 | .name = "ubd", |
832 | .config = ubd_config, | 833 | .config = ubd_config, |
833 | .get_config = ubd_get_config, | 834 | .get_config = ubd_get_config, |
diff --git a/arch/um/kernel/tt/gdb_kern.c b/arch/um/kernel/tt/gdb_kern.c index a1af96ef9ee2..03b06bc00771 100644 --- a/arch/um/kernel/tt/gdb_kern.c +++ b/arch/um/kernel/tt/gdb_kern.c | |||
@@ -12,6 +12,7 @@ extern int gdb_config(char *str, char **error_out); | |||
12 | extern int gdb_remove(int n, char **error_out); | 12 | extern int gdb_remove(int n, char **error_out); |
13 | 13 | ||
14 | static struct mc_device gdb_mc = { | 14 | static struct mc_device gdb_mc = { |
15 | .list = INIT_LIST_HEAD(gdb_mc.list), | ||
15 | .name = "gdb", | 16 | .name = "gdb", |
16 | .config = gdb_config, | 17 | .config = gdb_config, |
17 | .remove = gdb_remove, | 18 | .remove = gdb_remove, |