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: 170546 Delivered-To: patch@linaro.org Received: by 2002:ac9:2daa:0:0:0:0:0 with SMTP id g42csp4163198oce; Mon, 5 Aug 2019 06:31:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyT/ABxwGeRAsCCnL+tPndvlRvicgRVKorf7Ex6zFjpPc4rrHpZDDVX2GzXnw4km0q9rw9S X-Received: by 2002:a02:cc6c:: with SMTP id j12mr108392898jaq.102.1565011883752; Mon, 05 Aug 2019 06:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565011883; cv=none; d=google.com; s=arc-20160816; b=IOpS5jahLuFhLQZXBceyGGtygDrcg9C3YQfEtPRti6xIsvI504S8XRAsC1A8Gqh7Hd TwFFP6s+l+EDDfdzUSc4SY9N2Rt7XdjUYRXqjN13FI4S+eWrUUStZI8Mxx1DXcvpDr5j iaZ00oxFpoNf8EzOTZiYWPl3phwVyO/PnU+Mo/1X7921agGvAFy1+OqC+v6pCggxhWvM jbL6etV7I6dV+wmv6uV4fyWUJH6RLBeF5/xxLdmQdAt3ezZpeSgF5+1hdGzzQQzxE2KF NRu6dflG3voq86kCa5j8A8YNPmV7PzXyuN72llwhVal40YJ0QNS51hcs2u1+kmhs6gPo lUgg== 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=IyhcvQXH9gW2tGONV+gE7mCtMvi8mRRFFf/Go7z1NhE=; b=0LvIu4tRH08Z4lGTA2Wf5EXq4RdkWA3sYt82z/HJHJlYpyHvlOCHiR7tAPXXyq9avV zmbPlXK3XpedKvQD6iUJxUCLXCX5aZNewytxNYX8GsBu9JLN5jImRx1KHiCPmg2tnSV4 V/Ihi0Om+xSsXKWLeizbVRenTy+UC2vCdVJjXyp6C3caG0JXiZ3mDCVtjUx2knZNd91P N7K/oTL/4b+MLu42AKXQ9XMwzhCfROH1Nr0rajjFoJSKl1c8tSe89d7UFpBYAXjGYVG6 rX9tA6oivl17Y572dcWJ9O4hNBm1exqg72lsFoWAcuPwFOgW5/Vlh3MJJhlC5e9dC2Fi c4CQ== 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 191si114953112jay.46.2019.08.05.06.31.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Aug 2019 06:31:23 -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 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" 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