aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Gortmaker <paul.gortmaker@windriver.com>2014-01-14 16:03:37 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-02-13 13:41:47 -0500
commitf76a1cbed18c86e2d192455f0daebb48458965f3 (patch)
tree6372a788551489c9fc68dfb82627c1970bdde4b1
parent9be16b38cf43181efc12ee6f467aaf222ad31b03 (diff)
hvc: ensure hvc_init is only ever called once in hvc_console.c
Commit 3e6c6f630a5282df8f3393a59f10eb9c56536d23 ("Delay creation of khcvd thread") moved the call of hvc_init from being a device_initcall into hvc_alloc, and used a non-null hvc_driver as indication of whether hvc_init had already been called. The problem with this is that hvc_driver is only assigned a value at the bottom of hvc_init, and so there is a window where multiple hvc_alloc calls can be in progress at the same time and hence try and call hvc_init multiple times. Previously the use of device_init guaranteed that hvc_init was only called once. This manifests itself as sporadic instances of two hvc_init calls racing each other, and with the loser of the race getting -EBUSY from tty_register_driver() and hence that virtual console fails: Couldn't register hvc console driver virtio-ports vport0p1: error -16 allocating hvc for port Here we add an atomic_t to guarantee we'll never run hvc_init twice. Cc: stable@vger.kernel.org # v2.6.24+ Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Fixes: 3e6c6f630a52 ("Delay creation of khcvd thread") Reported-by: Jim Somerville <Jim.Somerville@windriver.com> Tested-by: Jim Somerville <Jim.Somerville@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/hvc/hvc_console.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index 50b46881b6ca..94f9e3a38412 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -31,6 +31,7 @@
31#include <linux/list.h> 31#include <linux/list.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/major.h> 33#include <linux/major.h>
34#include <linux/atomic.h>
34#include <linux/sysrq.h> 35#include <linux/sysrq.h>
35#include <linux/tty.h> 36#include <linux/tty.h>
36#include <linux/tty_flip.h> 37#include <linux/tty_flip.h>
@@ -70,6 +71,9 @@ static struct task_struct *hvc_task;
70/* Picks up late kicks after list walk but before schedule() */ 71/* Picks up late kicks after list walk but before schedule() */
71static int hvc_kicked; 72static int hvc_kicked;
72 73
74/* hvc_init is triggered from hvc_alloc, i.e. only when actually used */
75static atomic_t hvc_needs_init __read_mostly = ATOMIC_INIT(-1);
76
73static int hvc_init(void); 77static int hvc_init(void);
74 78
75#ifdef CONFIG_MAGIC_SYSRQ 79#ifdef CONFIG_MAGIC_SYSRQ
@@ -851,7 +855,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
851 int i; 855 int i;
852 856
853 /* We wait until a driver actually comes along */ 857 /* We wait until a driver actually comes along */
854 if (!hvc_driver) { 858 if (atomic_inc_not_zero(&hvc_needs_init)) {
855 int err = hvc_init(); 859 int err = hvc_init();
856 if (err) 860 if (err)
857 return ERR_PTR(err); 861 return ERR_PTR(err);