All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: [PATCH 1/4] xen/console: Properly buffer domU output when using CONSOLEIO_write
Date: Tue,  2 Apr 2019 17:42:35 +0100	[thread overview]
Message-ID: <20190402164238.1815-2-julien.grall@arm.com> (raw)
In-Reply-To: <20190402164238.1815-1-julien.grall@arm.com>

The output will be buffered if the buffer provided by the DomU does not
contain a newline. This can also happen if buffer provided by DomU is
split in multiple part (Xen can only process 127 characters at the time).

As Xen will remove any non-printable characters, the output buffer may
be smaller than the buffer provided. However, Xen will buffer using the
original length. This means that the NUL character and garbagge will be
copied in the internal buffer.

Once the newline is found or the internal buffer is full, only part of
the internal buffer will end up to be printed.

An easy way to reproduce it is:

HYPERVISOR_consoleio(CONSOLEIO_write, "\33", 1);
HYPERVISOR_consoleio(CONSOLEIO_write, "d", 1);
HYPERVISOR_consoleio(CONSOLEIO_write, "\n", 1);

In the current code, the character 'd' will not be printed.

This problem can be solved by computing the size of the output buffer
(i.e the buffer without the non-printable characters).

Signed-off-by: Julien Grall <julien.grall@arm.com>

---

I is possible to compute (kout - kbuf) only once. I didn't do it because
I wasn't able to find a good name.
---
 xen/drivers/char/console.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 5f0f54201b..9bbcb0f57a 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -592,11 +592,11 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, int count)
                 guest_printk(cd, XENLOG_G_DEBUG "%s%s\n", cd->pbuf, kbuf);
                 cd->pbuf_idx = 0;
             }
-            else if ( cd->pbuf_idx + kcount < (DOMAIN_PBUF_SIZE - 1) )
+            else if ( cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE - 1) )
             {
                 /* buffer the output until a newline */
-                memcpy(cd->pbuf + cd->pbuf_idx, kbuf, kcount);
-                cd->pbuf_idx += kcount;
+                memcpy(cd->pbuf + cd->pbuf_idx, kbuf, kout - kbuf);
+                cd->pbuf_idx += (kout - kbuf);
             }
             else
             {
-- 
2.11.0


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

  reply	other threads:[~2019-04-02 16:42 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02 16:42 [PATCH 0/4] xen/console: Bug fixes and doc improvement Julien Grall
2019-04-02 16:42 ` Julien Grall [this message]
2019-04-03 11:41   ` [PATCH 1/4] xen/console: Properly buffer domU output when using CONSOLEIO_write Wei Liu
2019-04-09 10:25     ` Julien Grall
2019-04-09 10:25       ` [Xen-devel] " Julien Grall
2019-04-02 16:42 ` [PATCH 2/4] xen/console: Don't treat NUL character as the end of the buffer Julien Grall
2019-04-02 17:49   ` Andrew Cooper
2019-04-03  7:59     ` Jan Beulich
2019-04-09 10:31       ` Julien Grall
2019-04-09 10:31         ` [Xen-devel] " Julien Grall
2019-04-05 10:00   ` Jan Beulich
2019-04-05 10:00     ` [Xen-devel] " Jan Beulich
2019-04-05 10:21     ` Julien Grall
2019-04-05 10:21       ` [Xen-devel] " Julien Grall
2019-04-05 10:26       ` Jan Beulich
2019-04-05 10:26         ` [Xen-devel] " Jan Beulich
2019-04-16 20:33   ` Stefano Stabellini
2019-04-16 20:33     ` [Xen-devel] " Stefano Stabellini
2019-08-05 11:40     ` Julien Grall
2019-04-02 16:42 ` [PATCH 3/4] xen/public: Document HYPERCALL_console_io() Julien Grall
2019-04-03 11:41   ` Wei Liu
2019-04-03 13:04   ` Jan Beulich
2019-04-09 11:26     ` Julien Grall
2019-04-09 11:26       ` [Xen-devel] " Julien Grall
2019-04-09 11:42       ` Jan Beulich
2019-04-09 11:42         ` [Xen-devel] " Jan Beulich
2019-04-16  9:54         ` Julien Grall
2019-04-16  9:54           ` [Xen-devel] " Julien Grall
2019-04-25 10:09           ` Jan Beulich
2019-04-25 10:09             ` [Xen-devel] " Jan Beulich
2019-04-16 10:29         ` Ian Jackson
2019-04-16 10:29           ` [Xen-devel] " Ian Jackson
2019-08-05  9:40         ` Julien Grall
2019-08-05 10:07           ` Jan Beulich
2019-08-05 10:17             ` Julien Grall
2019-08-05 10:21               ` Jan Beulich
2019-04-16 20:42   ` Stefano Stabellini
2019-04-16 20:42     ` [Xen-devel] " Stefano Stabellini
2019-04-02 16:42 ` [PATCH 4/4] xen/console: Simplify domU console handling in guest_console_write Julien Grall
2019-04-03 11:42   ` Wei Liu
2019-04-16 20:48   ` Stefano Stabellini
2019-04-16 20:48     ` [Xen-devel] " Stefano Stabellini

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=20190402164238.1815-2-julien.grall@arm.com \
    --to=julien.grall@arm.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=konrad.wilk@oracle.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.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.