From patchwork Mon Oct 16 09:02:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 10007899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D114E60235 for ; Mon, 16 Oct 2017 09:05:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3CCF283D9 for ; Mon, 16 Oct 2017 09:05:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B86CC283ED; Mon, 16 Oct 2017 09:05:52 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E3A4027FBC for ; Mon, 16 Oct 2017 09:05:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e41IY-0003hT-Lk; Mon, 16 Oct 2017 09:02:58 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e41IX-0003hN-BZ for xen-devel@lists.xenproject.org; Mon, 16 Oct 2017 09:02:57 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id 7B/47-29298-0C574E95; Mon, 16 Oct 2017 09:02:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCIsWRWlGSWpSXmKPExsVyMfTAKt39pU8 iDX7PN7L4vmUykwOjx+EPV1gCGKNYM/OS8isSWDOu/7zMWLDEvmLrocdMDYxHjLsYOTmEBGYw Stw+JdjFyMXBItDOLPFw+jEWkISEwDsWiR23NCDsPIn1S14yQ9hpEv8XnmGDsCskZr5azAYxS Evi6KnZrCCDhAR2MknM/vYEyOHgYBMwkZjVIQFSIyKgJHFv1WQmkBpmgbeMEgv33GQFSQgLpE g0HJ/MDmKzCKhKtB+aADaUV8BbYln3U0aIZXISN891Mk9g5F/AyLCKUb04tagstUjXQi+pKDM 9oyQ3MTNH19DAVC83tbg4MT01JzGpWC85P3cTIzB8GIBgB+PBZudDjJIcTEqivM6GTyKF+JLy UyozEosz4otKc1KLDzHKcHAoSfBGlADlBItS01Mr0jJzgIEMk5bg4FES4U0CSfMWFyTmFmemQ 6ROMdpzXLhz6Q8Tx7FNl4HkgT23gGTHzbt/mIRY8vLzUqXEeRNB2gRA2jJK8+CGwiLvEqOslD AvI9CZQjwFqUW5mSWo8q8YxTkYlYR580Cm8GTmlcDtfgV0FhPQWeucwM4qSURISTUw+j0Nurb S8UddCn+0UL1MlEvdaa2FLjXu52I+RK7/NbnvsvePDdJVNyTf77gwxahqshzPkZLTNYxGM/7N UHMvFn98afta5vcbLG/VrN7mcmxKcss5t9TDwnN1mRIuvGMuntu1O83IROzUr6D2zTWJrtoeQ sVPOKVzT17P+1xR16r3PFOb1VNLiaU4I9FQi7moOBEAJzQio7cCAAA= X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-16.tower-206.messagelabs.com!1508144574!91229075!1 X-Originating-IP: [209.85.192.170] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8143 invoked from network); 16 Oct 2017 09:02:55 -0000 Received: from mail-pf0-f170.google.com (HELO mail-pf0-f170.google.com) (209.85.192.170) by server-16.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 16 Oct 2017 09:02:55 -0000 Received: by mail-pf0-f170.google.com with SMTP id a8so14899888pfc.0 for ; Mon, 16 Oct 2017 02:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=zYDBk2xhLpL4uqPNvfV0c4gOF4FP6g+9GLNojPElqs0=; b=VEZFx9nFxCiltKfCDfNZmxubgzK/vPLC9OxsnkaVcvpVDSJFlPajyGbRBPAS05aClU 6/jup2TfKh2tMiVxt4YaSVCqubjIAHgwBLXYkfL1mQ4Lo6vJFA+bjpdjk7eb+9wC3Dnn nJGViGZIbNpWRSoHHCUEFzXSoPWpq0p00R2Rg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zYDBk2xhLpL4uqPNvfV0c4gOF4FP6g+9GLNojPElqs0=; b=tX+5BWW0/R4GtBrEnDT92vE8INidOJShAkkhsDj0oUNdjA5CY5Skepv8Hrx1NNnpbb mNsE7vHDIpXEfBEuQkcJ+SAnbfBprFKMAMX2g2fJD7sjWQc48yqEK4HPnHWX2196A5rf H0naXyiCQPRZFCJ2Hoad9UHz2SN5jMDoPM+LQLa4RocnpO1UwMJtOZTSbtdCxP+fjprL dPhS74Qdx/Lov2n4yUdG1XR994Wq4E5KA7dZ3CQvAmfjFqGvlDleFXM80SxN/IiYXAun WL7nesh4G3ZwbZ3zdMCKAG8+e0+dfoKkIuHpCxBz4sKGrWdCDjxEugqopBDCXWte0bE6 ZojA== X-Gm-Message-State: AMCzsaWPdlY6rS2n3X4/ZNdq75K9b1RjZWM3TFGoPl9IxnCUdFcoWwcm /g+oKH4XT4SBfvvQ+ie75q4ExyM/p4g= X-Google-Smtp-Source: AOwi7QAyJCFRYwhRdMsfApyx2yXUY7tW45XyzFgA9KTc1tRRAs3A0Shbi5LK2G8W+YKYB5LeEcYDtQ== X-Received: by 10.98.0.206 with SMTP id 197mr8001637pfa.194.1508144573677; Mon, 16 Oct 2017 02:02:53 -0700 (PDT) Received: from blr-ubuntu-linaro.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id p12sm12353249pgn.90.2017.10.16.02.02.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Oct 2017 02:02:53 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Mon, 16 Oct 2017 14:32:47 +0530 Message-Id: <1508144567-23300-1-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 Cc: Stefano Stabellini , Wei Liu , Andrew Cooper , Ian Jackson , Julien Grall , Jan Beulich Subject: [Xen-devel] libxl/xenconsole: vpl011: Fix hex to dec conversion of vuart_gfn in libxl__device_vuart_add X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In libxl__device_vuart_add vuart_gfn is getting stored as a hex value: > flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn)); However, xenstore reads this value as a decimal value and tries to map the wrong address and fails. Introduced a new format string "PRIu_xen_pfn" which formats the value as a decimal value. Also corrected the type of ring_ref to xen_pfn_t in xenconsole. Signed-off-by: Bhupinder Thakur --- This patch was verified for arm64 and arm32 toolstack compilation. CC: Ian Jackson CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Jan Beulich CC: Andrew Cooper tools/console/daemon/io.c | 20 +++++++++++--------- tools/libxc/include/xenctrl_compat.h | 2 +- tools/libxc/xc_foreign_memory.c | 2 +- tools/libxl/libxl_console.c | 4 ++-- tools/libxl/libxl_dom.c | 2 +- tools/libxl/libxl_internal.h | 2 +- xen/include/public/arch-arm.h | 1 + xen/include/public/arch-x86/xen.h | 1 + 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index e22009a..6369bf4 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -80,6 +80,7 @@ static unsigned int current_array_size; static unsigned int nr_fds; #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) +#define INVALID_RING_REF (~(xen_pfn_t)0) struct buffer { char *data; @@ -98,7 +99,7 @@ struct console { struct buffer buffer; char *xspath; char *log_suffix; - int ring_ref; + xen_pfn_t ring_ref; xenevtchn_handle *xce_handle; int xce_pollfd_idx; int event_count; @@ -651,22 +652,23 @@ static void console_unmap_interface(struct console *con) { if (con->interface == NULL) return; - if (xgt_handle && con->ring_ref == -1) + if (xgt_handle && con->ring_ref == INVALID_RING_REF) xengnttab_unmap(xgt_handle, con->interface, 1); else munmap(con->interface, XC_PAGE_SIZE); con->interface = NULL; - con->ring_ref = -1; + con->ring_ref = INVALID_RING_REF; } static int console_create_ring(struct console *con) { - int err, remote_port, ring_ref, rc; + int err, remote_port, rc; + xen_pfn_t ring_ref; char *type, path[PATH_MAX]; struct domain *dom = con->d; err = xs_gather(xs, con->xspath, - "ring-ref", "%u", &ring_ref, + "ring-ref", "%i", &ring_ref, "port", "%i", &remote_port, NULL); @@ -690,7 +692,7 @@ static int console_create_ring(struct console *con) free(type); /* If using ring_ref and it has changed, remap */ - if (ring_ref != con->ring_ref && con->ring_ref != -1) + if (ring_ref != con->ring_ref && con->ring_ref != INVALID_RING_REF) console_unmap_interface(con); if (!con->interface && xgt_handle && con->use_gnttab) { @@ -698,14 +700,14 @@ static int console_create_ring(struct console *con) con->interface = xengnttab_map_grant_ref(xgt_handle, dom->domid, GNTTAB_RESERVED_CONSOLE, PROT_READ|PROT_WRITE); - con->ring_ref = -1; + con->ring_ref = INVALID_RING_REF; } if (!con->interface) { /* Fall back to xc_map_foreign_range */ con->interface = xc_map_foreign_range( xc, dom->domid, XC_PAGE_SIZE, PROT_READ|PROT_WRITE, - (unsigned long)ring_ref); + ring_ref); if (con->interface == NULL) { err = EINVAL; goto out; @@ -804,7 +806,7 @@ static int console_init(struct console *con, struct domain *dom, void **data) con->master_pollfd_idx = -1; con->slave_fd = -1; con->log_fd = -1; - con->ring_ref = -1; + con->ring_ref = INVALID_RING_REF; con->local_port = -1; con->remote_port = -1; con->xce_pollfd_idx = -1; diff --git a/tools/libxc/include/xenctrl_compat.h b/tools/libxc/include/xenctrl_compat.h index a655e47..2d930d8 100644 --- a/tools/libxc/include/xenctrl_compat.h +++ b/tools/libxc/include/xenctrl_compat.h @@ -26,7 +26,7 @@ */ void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, int size, int prot, - unsigned long mfn ); + xen_pfn_t mfn ); void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot, const xen_pfn_t *arr, int num ); diff --git a/tools/libxc/xc_foreign_memory.c b/tools/libxc/xc_foreign_memory.c index 4053d26..8b65e52 100644 --- a/tools/libxc/xc_foreign_memory.c +++ b/tools/libxc/xc_foreign_memory.c @@ -33,7 +33,7 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot, void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, int size, int prot, - unsigned long mfn) + xen_pfn_t mfn) { xen_pfn_t *arr; int num; diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c index c05dc28..f2ca689 100644 --- a/tools/libxl/libxl_console.c +++ b/tools/libxl/libxl_console.c @@ -329,7 +329,7 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid, flexarray_append(ro_front, "port"); flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->console_port)); flexarray_append(ro_front, "ring-ref"); - flexarray_append(ro_front, GCSPRINTF("%lu", state->console_mfn)); + flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, state->console_mfn)); } else { flexarray_append(front, "state"); flexarray_append(front, GCSPRINTF("%d", XenbusStateInitialising)); @@ -376,7 +376,7 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid, flexarray_append(ro_front, "port"); flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port)); flexarray_append(ro_front, "ring-ref"); - flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn)); + flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, state->vuart_gfn)); flexarray_append(ro_front, "limit"); flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT)); flexarray_append(ro_front, "type"); diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index ef834e6..a58e74f 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -869,7 +869,7 @@ out: static int hvm_build_set_params(xc_interface *handle, uint32_t domid, libxl_domain_build_info *info, int store_evtchn, unsigned long *store_mfn, - int console_evtchn, unsigned long *console_mfn, + int console_evtchn, xen_pfn_t *console_mfn, domid_t store_domid, domid_t console_domid) { struct hvm_info_table *va_hvm; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 45e6df6..f52aeb3 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1128,7 +1128,7 @@ typedef struct { uint32_t console_port; uint32_t console_domid; - unsigned long console_mfn; + xen_pfn_t console_mfn; char *console_tty; char *saved_state; diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 5708cd2..05fd11c 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -274,6 +274,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t); typedef uint64_t xen_pfn_t; #define PRI_xen_pfn PRIx64 +#define PRIu_xen_pfn PRIu64 /* Maximum number of virtual CPUs in legacy multi-processor guests. */ /* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */ diff --git a/xen/include/public/arch-x86/xen.h b/xen/include/public/arch-x86/xen.h index ff91831..3b0b1d6 100644 --- a/xen/include/public/arch-x86/xen.h +++ b/xen/include/public/arch-x86/xen.h @@ -75,6 +75,7 @@ __DeFiNe__ __DECL_REG_LO16(name) e ## name #ifndef __ASSEMBLY__ typedef unsigned long xen_pfn_t; #define PRI_xen_pfn "lx" +#define PRIu_xen_pfn "lu" #endif #define XEN_HAVE_PV_GUEST_ENTRY 1