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 v2 1/3] virtio_console: Fix locking of vtermno.

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH v2 1/3] virtio_console: Fix locking of vtermno.
From: Miche Baker-Harvey <miche@xxxxxxxxxx>
Date: Tue, 08 Nov 2011 11:29:38 -0800
Delivery-date: Mon, 14 Nov 2011 15:42:06 -0800
Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1320780579; bh=GlhtrWTykXbYchBGd1i5vetoUOE=; h=Subject:To:From:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; b=vOLjhRJXidIBPEugaDd1TPRAWUOrFILKoi33n/bISNRrqunGNMUuEt8oWugnhrgyQ E1hfy3Mqr/Li/rUfbSEhg==
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=jsn0D6y8ISuX9AVX/HK8FdeEXyM5q2MplyhCWwlKW4ttbJ7wxPMkx0Qv38/Tbt1XQ wLojKOw2jghFKElTXMeqQ==
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <20111108192932.30528.88994.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: <20111108192932.30528.88994.stgit@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: StGit/0.15
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 <miche@xxxxxxxxxx>
---
 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;


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

<Prev in Thread] Current Thread [Next in Thread>