All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anshul Makkar <anshul.makkar@citrix.com>
To: xen-devel@lists.xen.org
Cc: ian.jackson@eu.citrix.com,
	Anshul Makkar <anshul.makkar@citrix.com>,
	wei.liu2@citrix.com, jbeulich@suse.com,
	andrew.cooper3@citrix.com
Subject: [[PATCH -v2]] XenBus: Don't wait for the producer to fill the ring if
Date: Tue, 23 May 2017 15:12:58 +0100	[thread overview]
Message-ID: <1495548778-10744-1-git-send-email-anshul.makkar@citrix.com> (raw)

The condition: if there is a space in the ring then wait for the producer
to fill the ring also evaluates to true even if the ring if full. It
leads to a deadlock where producer is waiting for consumer
to consume the items and consumer is waiting for producer to fill the ring.

Fix for the issue: check if the ring is full and then break from
the loop to consume the items from the ring.
eg. case: prod = 1272, cons = 248.

Signed-off-by: Anshul Makkar <anshul.makkar@citrix.com>
---
v2:
 * resolved the coding style issue.
 * modified the "if" condition statement to make it simpler.

 tools/firmware/hvmloader/xenbus.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/firmware/hvmloader/xenbus.c b/tools/firmware/hvmloader/xenbus.c
index 448157d..2b89a56 100644
--- a/tools/firmware/hvmloader/xenbus.c
+++ b/tools/firmware/hvmloader/xenbus.c
@@ -141,7 +141,19 @@ static void ring_read(char *data, uint32_t len)
         /* Don't overrun the producer pointer */
         while ( (part = MASK_XENSTORE_IDX(rings->rsp_prod -
                                           rings->rsp_cons)) == 0 )
+        {
+            /*
+             * Don't wait for producer to fill the ring if it is already full.
+             * Condition happens when you write string > 1K into the ring.
+             * eg case prod=1272 cons=248.
+             */
+            if ( rings->rsp_prod - rings->rsp_cons == XENSTORE_RING_SIZE )
+            {
+                part = XENSTORE_RING_SIZE;
+                break;
+            }
             ring_wait();
+        }
         /* Don't overrun the end of the ring */
         if ( part > (XENSTORE_RING_SIZE - MASK_XENSTORE_IDX(rings->rsp_cons)) )
             part = XENSTORE_RING_SIZE - MASK_XENSTORE_IDX(rings->rsp_cons);
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

             reply	other threads:[~2017-05-23 14:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-23 14:12 Anshul Makkar [this message]
2017-05-23 15:14 ` [[PATCH -v2]] XenBus: Don't wait for the producer to fill the ring if Jan Beulich
2017-05-24 14:16   ` Andrew Cooper
2017-05-25  7:29     ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1495548778-10744-1-git-send-email-anshul.makkar@citrix.com \
    --to=anshul.makkar@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.