From patchwork Tue Apr 2 16:42:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 161640 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1963937jan; Tue, 2 Apr 2019 09:44:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTkshKZjbxy1QE6zSxfgVWWUUH0w+ydzwLsCsGSQWVEs216NsSoGSM4wx1l18Wy3kph4sy X-Received: by 2002:a81:99cc:: with SMTP id q195mr15653823ywg.148.1554223462810; Tue, 02 Apr 2019 09:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554223462; cv=none; d=google.com; s=arc-20160816; b=IBBT2vDZksJ8nJssrGzVF6a8f5f1gOdU/skHb4Zwvincja5zjeSFiZxkDlEJ+VaoM4 f2Ctq7mE2idsZZpcjKKPPqiHPYhMVLIVf6YvpPv1KnxOyZuGBsBGgsP8tnXClYf+TQre 6a1vGo/V+0hKUzfjWH9o6CuIYlOu2LVP3WuKZIfJx14m0lUMHWOTAtloQsMdcPQPzjWR csM5IUXi2f1rggo5GjdBc+RWUvk9c/Mzn0EPOmHSg5fRYet0glU9h7ceGGpCl+wHos7j NuN3ghXCmb2bvgJYtyC4SxqImLSdpxBamNXKKefB5OqEZRr3XSs/MbnZVfda1qr1czWa dwmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=6pJfehEtlmsIxO8D0RNxY4VPG5SNaCo8zwnZzO3jR/E=; b=iuQwHv9mijt2R2e3nu1HtAlCjMMkh8UPRajOqyDFEPUY37HZljYCGv10Q002zNZl5d HvV9rjZ2BJui0KWzlu/OQWM7pg4QUPPxQtLCHURp2t3Gx6fRNwj9juHqOT4XpHxqdy/M gULB1IXdDf4xq2ggTGoRp3sTwAHeOAdtP4GGUjT09r1KzcPTnc4WLDKLFLde3xG5bie4 SmLS01rhw5CyguVArIAVn09ydYRyxRSEhB6AajV0tWWCwGPBds0o2XZpK2zGvEH5Lyew yZtcDggSY/7g/8TP3nAuKzyktAR9pjdwv5v4JwxrErI51vpPyRkJoZUvy63U9QVU8eDx 4w5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x135si8264287ywx.266.2019.04.02.09.44.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 09:44:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hBMUz-0005xN-HK; Tue, 02 Apr 2019 16:42:57 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hBMUx-0005xE-Ci for xen-devel@lists.xenproject.org; Tue, 02 Apr 2019 16:42:55 +0000 X-Inumbo-ID: 5c966952-5566-11e9-b7e8-d3463b65a21f Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 5c966952-5566-11e9-b7e8-d3463b65a21f; Tue, 02 Apr 2019 16:42:54 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 953A315AD; Tue, 2 Apr 2019 09:42:53 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C86163F721; Tue, 2 Apr 2019 09:42:51 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 2 Apr 2019 17:42:35 +0100 Message-Id: <20190402164238.1815-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190402164238.1815-1-julien.grall@arm.com> References: <20190402164238.1815-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 1/4] xen/console: Properly buffer domU output when using CONSOLEIO_write X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 Acked-by: Wei Liu --- 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 {