From patchwork Mon Aug 5 13:29:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 11076889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15402746 for ; Mon, 5 Aug 2019 13:31:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0549928711 for ; Mon, 5 Aug 2019 13:31:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED82B288E5; Mon, 5 Aug 2019 13:31:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 465FD28711 for ; Mon, 5 Aug 2019 13:31:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3v-0004rp-GI; Mon, 05 Aug 2019 13:30:07 +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 1hud3t-0004mH-S7 for xen-devel@lists.xenproject.org; Mon, 05 Aug 2019 13:30:05 +0000 X-Inumbo-ID: 2247a2a8-b785-11e9-baf5-930cb7644b7c Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 2247a2a8-b785-11e9-baf5-930cb7644b7c; Mon, 05 Aug 2019 13:30:04 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2657A1597; Mon, 5 Aug 2019 06:30:04 -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 C525C3F706; Mon, 5 Aug 2019 06:30:02 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 5 Aug 2019 14:29:53 +0100 Message-Id: <20190805132955.1630-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190805132955.1630-1-julien.grall@arm.com> References: <20190805132955.1630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v2 2/4] xen/console: Rework HYPERCALL_console_io interface 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" X-Virus-Scanned: ClamAV using ClamSMTP At the moment, HYPERCALL_console_io is using signed int to describe the command (@cmd) and the size of the buffer (@count). * @cmd does not need to be signed this used as a set of named value. None of them are negative. If new one are introduced they can be positive. * @count is used to know the size of the buffer. It makes little sense to have a negative value here. So both variables are now switched to use unsigned int. Changing @count to unsigned type will result in a change of behavior for the existing commands: - write: Any buffer bigger than 2GB will now be printed rather than been ignored (the command return 0). - read: The return value is a signed 32-bit value for 32-bit Xen. To keep compatibility between 32-bit and 64-bit ABI, it effectively means the return value is 32-bit (despite been long on 64-bit). Negative value are used for error and positive value for the number of characters read. To avoid clash between the two sets, the buffer is still limited to 2GB. The only difference is an error is returned rather than claiming there are no characters. The behavior is only affecting unlikely use of the current interface, so this is not a big concern regarding backward compatibility. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich --- This will be documented in the public interface in the next patch. Changes in v2: - Patch added --- xen/drivers/char/console.c | 15 +++++++++++++-- xen/include/xen/hypercall.h | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 752a11f6c5..fa8f5cff4b 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -524,7 +524,8 @@ static inline void xen_console_write_debug_port(const char *buf, size_t len) } #endif -static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, int count) +static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, + unsigned int count) { char kbuf[128]; unsigned int kcount = 0; @@ -612,7 +613,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, int count) return 0; } -long do_console_io(int cmd, int count, XEN_GUEST_HANDLE_PARAM(char) buffer) +long do_console_io(unsigned int cmd, unsigned int count, + XEN_GUEST_HANDLE_PARAM(char) buffer) { long rc; unsigned int idx, len; @@ -627,6 +629,15 @@ long do_console_io(int cmd, int count, XEN_GUEST_HANDLE_PARAM(char) buffer) rc = guest_console_write(buffer, count); break; case CONSOLEIO_read: + /* + * The return value is either the number of characters read or + * a negative value in case of error. So we need to prevent + * overlap between the two sets. + */ + rc = -E2BIG; + if ( (int)count < 0 ) + break; + rc = 0; while ( (serial_rx_cons != serial_rx_prod) && (rc < count) ) { diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h index fc00a67448..ad8ad27b23 100644 --- a/xen/include/xen/hypercall.h +++ b/xen/include/xen/hypercall.h @@ -83,8 +83,8 @@ do_xen_version( extern long do_console_io( - int cmd, - int count, + unsigned int cmd, + unsigned int count, XEN_GUEST_HANDLE_PARAM(char) buffer); extern long