aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/mconsole_kern.c
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-02-10 04:44:01 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-11 13:51:21 -0500
commit84f48d4f2b511db15fda67fd38462b91abd0af53 (patch)
tree7de15447387c3ace3dfda3b4dabc0b6d3dd1c643 /arch/um/drivers/mconsole_kern.c
parentd471c0fca7eae1ffd4f7d4c11ee835ff70aaa71f (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/drivers/mconsole_kern.c')
-rw-r--r--arch/um/drivers/mconsole_kern.c21
1 files changed, 15 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. */ 340static DEFINE_SPINLOCK(mc_devices_lock);
341
342static LIST_HEAD(mconsole_devices); 341static LIST_HEAD(mconsole_devices);
343 342
344void mconsole_register_dev(struct mc_device *new) 343void 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
349static struct mc_device *mconsole_find_dev(char *name) 351static 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
372static DECLARE_MUTEX(plug_mem_mutex);
370static unsigned long long unplugged_pages_count = 0; 373static unsigned long long unplugged_pages_count = 0;
371static struct list_head unplugged_pages = LIST_HEAD_INIT(unplugged_pages); 374static struct list_head unplugged_pages = LIST_HEAD_INIT(unplugged_pages);
372static int unplug_index = UNPLUGGED_PER_PAGE; 375static 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;
464out_unlock:
465 up(&plug_mem_mutex);
460out: 466out:
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
489static struct mc_device mem_mc = { 495static 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
632static DEFINE_SPINLOCK(console_lock); 639static DEFINE_SPINLOCK(client_lock);
633static LIST_HEAD(clients); 640static LIST_HEAD(clients);
634static char console_buf[MCONSOLE_MAX_DATA]; 641static char console_buf[MCONSOLE_MAX_DATA];
635static int console_index = 0; 642static 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