From patchwork Tue Nov 8 19:30:11 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: 124421 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 9CA3E100DA1 for ; Wed, 9 Nov 2011 06:30:35 +1100 (EST) Received: from smtp-out.google.com (smtp-out.google.com [74.125.121.67]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B345210096A for ; Wed, 9 Nov 2011 06:30:19 +1100 (EST) Received: from wpaz21.hot.corp.google.com (wpaz21.hot.corp.google.com [172.24.198.85]) by smtp-out.google.com with ESMTP id pA8JUD50009805 for ; Tue, 8 Nov 2011 11:30:13 -0800 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1320780614; bh=GlhtrWTykXbYchBGd1i5vetoUOE=; h=Subject:To:From:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; b=Be5nIjj975uVlqjVjrXYFho4+6MGBo2Hlf+UELL7teio0zJrN13ol+zKVyf2JlS0e YeBW/JLzDRqkGrkLysnwg== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=subject:to:from:date:message-id:in-reply-to:references: user-agent:mime-version:content-type: content-transfer-encoding:x-system-of-record; b=gQH2VSEgYz2GeASUuUBPnlYLGtoBwfIkNw+nFsM1M9Ld4Y26GznTaoVFPKulMt9tu xv05BzU3GvU231kRrHCrw== Received: from miche.sea.corp.google.com (miche.sea.corp.google.com [172.31.71.52]) by wpaz21.hot.corp.google.com with ESMTP id pA8JUCxo002109 for ; Tue, 8 Nov 2011 11:30:12 -0800 Received: from miche.sea.corp.google.com (localhost [IPv6:::1]) by miche.sea.corp.google.com (Postfix) with ESMTP id D2AE520253 for ; Tue, 8 Nov 2011 11:30:11 -0800 (PST) Subject: [PATCH v2 1/3] virtio_console: Fix locking of vtermno. To: ppc-dev From: Miche Baker-Harvey Date: Tue, 08 Nov 2011 11:30:11 -0800 Message-ID: <20111108193011.30707.39360.stgit@miche.sea.corp.google.com> In-Reply-To: <20111108193005.30707.23990.stgit@miche.sea.corp.google.com> References: <20111108193005.30707.23990.stgit@miche.sea.corp.google.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-System-Of-Record: true 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 Some modifications of vtermno were not done under the spinlock. Moved assignment from vtermno and increment of vtermno together, putting both under the spinlock. Revert vtermno on failure. Signed-off-by: Miche Baker-Harvey --- drivers/char/virtio_console.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 8e3c46d..9722e76 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -987,18 +987,21 @@ int init_port_console(struct port *port) * pointers. The final argument is the output buffer size: we * can do any size, so we put PAGE_SIZE here. */ - port->cons.vtermno = pdrvdata.next_vtermno; + spin_lock_irq(&pdrvdata_lock); + port->cons.vtermno = pdrvdata.next_vtermno++; + spin_unlock_irq(&pdrvdata_lock); port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE); + spin_lock_irq(&pdrvdata_lock); if (IS_ERR(port->cons.hvc)) { ret = PTR_ERR(port->cons.hvc); dev_err(port->dev, "error %d allocating hvc for port\n", ret); port->cons.hvc = NULL; + port->cons.vtermno = pdrvdata.next_vtermno--; + spin_unlock_irq(&pdrvdata_lock); return ret; } - spin_lock_irq(&pdrvdata_lock); - pdrvdata.next_vtermno++; list_add_tail(&port->cons.list, &pdrvdata.consoles); spin_unlock_irq(&pdrvdata_lock); port->guest_connected = true;