WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH v3 2/3] hvc_init(): Enforce one-time initialization.

To: Greg Kroah-Hartman <gregkh@xxxxxxx>
Subject: [Xen-devel] [PATCH v3 2/3] hvc_init(): Enforce one-time initialization.
From: Miche Baker-Harvey <miche@xxxxxxxxxx>
Date: Tue, 08 Nov 2011 13:45:04 -0800
Cc: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>, Rusty Russell <rusty@xxxxxxxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx, Anton Blanchard <anton@xxxxxxxxx>, Amit Shah <amit.shah@xxxxxxxxxx>, Mike Waychison <mikew@xxxxxxxxxx>, ppc-dev <linuxppc-dev@xxxxxxxxxxxxxxxx>, Eric Northrup <digitaleric@xxxxxxxxxx>
Delivery-date: Mon, 14 Nov 2011 15:47:07 -0800
Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1320788709; bh=SHfKR5wjANGLr1Amuy+0WF0U3b4=; h=Subject:To:From:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; b=hpg4NVKRarZF1Je5snObVDCvN/oKPYE6XzBtFXWr8Frt5xEzcWbs0u0GtgKV4aTaI 2W50cJ37OtGWaUYtxaNsA==
Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=subject:to:from:cc:date:message-id:in-reply-to:references: user-agent:mime-version:content-type: content-transfer-encoding:x-system-of-record; b=P2IJWqoLbOEGDxmchgpN04TOce/xKtFioi9STfTf+cbmwQI92q6t14ZNOCBfb3Vkg XCbvBVVzZSbglsMs9uKrg==
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <20111108214452.28884.14840.stgit@xxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <20111108214452.28884.14840.stgit@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: StGit/0.15
hvc_init() must only be called once, and no thread should continue with 
hvc_alloc()
until after initialization is complete.  The original code does not enforce 
either
of these requirements.  A new mutex limits entry to hvc_init() to a single 
thread,
and blocks all later comers until it has completed.

This patch fixes multiple crash symptoms.

Signed-off-by: Miche Baker-Harvey <miche@xxxxxxxxxx>
---
 drivers/tty/hvc/hvc_console.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index b6b2d18..09a6159 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -29,8 +29,9 @@
 #include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/list.h>
-#include <linux/module.h>
 #include <linux/major.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/sysrq.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
@@ -84,6 +85,10 @@ static LIST_HEAD(hvc_structs);
  * list traversal.
  */
 static DEFINE_SPINLOCK(hvc_structs_lock);
+/*
+ * only one task does allocation at a time.
+ */
+static DEFINE_MUTEX(hvc_ports_mutex);
 
 /*
  * This value is used to assign a tty->index value to a hvc_struct based
@@ -825,11 +830,15 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
        int i;
 
        /* We wait until a driver actually comes along */
+       mutex_lock(&hvc_ports_mutex);
        if (!hvc_driver) {
                int err = hvc_init();
-               if (err)
+               if (err) {
+                       mutex_unlock(&hvc_ports_mutex);
                        return ERR_PTR(err);
+               }
        }
+       mutex_unlock(&hvc_ports_mutex);
 
        hp = kzalloc(ALIGN(sizeof(*hp), sizeof(long)) + outbuf_size,
                        GFP_KERNEL);


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel