From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 03/11] mini-os/xenbus: Add missing locks to xb_write Date: Fri, 20 Jun 2014 20:04:42 +0100 Message-ID: <1403291090-8657-4-git-send-email-ian.jackson@eu.citrix.com> References: <1403291090-8657-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wy47V-0000qa-5t for xen-devel@lists.xenproject.org; Fri, 20 Jun 2014 19:05:05 +0000 In-Reply-To: <1403291090-8657-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Keir Fraser , Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org xb_write was missing any locking against concurrent calls. Signed-off-by: Ian Jackson --- xen/xenbus/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/xenbus/xenbus.c b/xen/xenbus/xenbus.c index 0958604..a06dc30 100644 --- a/xen/xenbus/xenbus.c +++ b/xen/xenbus/xenbus.c @@ -45,6 +45,7 @@ static struct xenstore_domain_interface *xenstore_buf; static DECLARE_WAIT_QUEUE_HEAD(xb_waitq); +static spinlock_t xb_lock = SPIN_LOCK_UNLOCKED; /* protects xenbus req ring */ DECLARE_WAIT_QUEUE_HEAD(xenbus_watch_queue); xenbus_event_queue xenbus_events; @@ -372,6 +373,8 @@ static void xb_write(int type, int req_id, xenbus_transaction_t trans_id, cur_req = &header_req; BUG_ON(len > XENSTORE_RING_SIZE); + + spin_lock(&xb_lock); /* Wait for the ring to drain to the point where we can send the message. */ prod = xenstore_buf->req_prod; @@ -380,9 +383,11 @@ static void xb_write(int type, int req_id, xenbus_transaction_t trans_id, /* Wait for there to be space on the ring */ DEBUG("prod %d, len %d, cons %d, size %d; waiting.\n", prod, len, xenstore_buf->req_cons, XENSTORE_RING_SIZE); + spin_unlock(&xb_lock); wait_event(xb_waitq, xenstore_buf->req_prod + len - xenstore_buf->req_cons <= XENSTORE_RING_SIZE); + spin_lock(&xb_lock); DEBUG("Back from wait.\n"); prod = xenstore_buf->req_prod; } @@ -419,6 +424,7 @@ static void xb_write(int type, int req_id, xenbus_transaction_t trans_id, wmb(); xenstore_buf->req_prod += len; + spin_unlock(&xb_lock); /* Send evtchn to notify remote */ notify_remote_via_evtchn(start_info.store_evtchn); -- 1.7.10.4