From patchwork Tue Nov 8 21:45:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miche Baker-Harvey X-Patchwork-Id: 124439 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 186C0100ACC for ; Wed, 9 Nov 2011 08:45:33 +1100 (EST) Received: from smtp-out.google.com (smtp-out.google.com [216.239.44.51]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 509BB1007D5 for ; Wed, 9 Nov 2011 08:45:21 +1100 (EST) Received: from hpaq5.eem.corp.google.com (hpaq5.eem.corp.google.com [172.25.149.5]) by smtp-out.google.com with ESMTP id pA8Lj9Pl005473; Tue, 8 Nov 2011 13:45:09 -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== Received: from miche.sea.corp.google.com (miche.sea.corp.google.com [172.31.71.52]) by hpaq5.eem.corp.google.com with ESMTP id pA8Lj5Wl017240; Tue, 8 Nov 2011 13:45:06 -0800 Received: from miche.sea.corp.google.com (localhost [IPv6:::1]) by miche.sea.corp.google.com (Postfix) with ESMTP id 9B406203B4; Tue, 8 Nov 2011 13:45:04 -0800 (PST) Subject: [PATCH v3 2/3] hvc_init(): Enforce one-time initialization. To: Greg Kroah-Hartman From: Miche Baker-Harvey Date: Tue, 08 Nov 2011 13:45:04 -0800 Message-ID: <20111108214504.28884.61814.stgit@miche.sea.corp.google.com> In-Reply-To: <20111108214452.28884.14840.stgit@miche.sea.corp.google.com> References: <20111108214452.28884.14840.stgit@miche.sea.corp.google.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-System-Of-Record: true Cc: Stephen Rothwell , xen-devel@lists.xensource.com, Konrad Rzeszutek Wilk , Rusty Russell , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Anton Blanchard , Amit Shah , Mike Waychison , ppc-dev , Eric Northrup X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org 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 --- 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 #include #include -#include #include +#include +#include #include #include #include @@ -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);