From patchwork Mon Dec 5 16:34:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 9461185 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 8F41B6022E for ; Mon, 5 Dec 2016 16:36:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B19F27A98 for ; Mon, 5 Dec 2016 16:36:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7001D27E5A; Mon, 5 Dec 2016 16:36: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=-4.2 required=2.0 tests=BAYES_00, 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 AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 175AC27A98 for ; Mon, 5 Dec 2016 16:36:45 +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 1cDwDb-0001On-Re; Mon, 05 Dec 2016 16:34:19 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cDwDa-0001OH-Qh for xen-devel@lists.xenproject.org; Mon, 05 Dec 2016 16:34:18 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 39/ED-08948-A0795485; Mon, 05 Dec 2016 16:34:18 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVyuP0Ovy7ndNc Ig+/35Cy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ox/W7vYC5oVKzru9LM1ML4X72Lk5JAQMJJ4 O/EfUxcjF4eQwEJGiYXHPzODJNgEVCU2XD/FCmKLCChJ3Fs1GayIWeAxo0Tz7j2MIAlhgUiJq 0ffs4PYLEAN1xq7wJp5BUwk2qf3MkFskJdYeP4ImM0pYCqxubOZBcQWAqrp/dnOPoGRewEjwy pG9eLUorLUIl1TvaSizPSMktzEzBxdQwMzvdzU4uLE9NScxKRiveT83E2MQP8yAMEOxumX/Q8 xSnIwKYnyTklwjRDiS8pPqcxILM6ILyrNSS0+xCjDwaEkwftuKlBOsCg1PbUiLTMHGGgwaQkO HiUR3t4pQGne4oLE3OLMdIjUKUZFKXHeNyB9AiCJjNI8uDZYcF9ilJUS5mUEOkSIpyC1KDezB FX+FaM4B6OSMC/rNKApPJl5JXDTXwEtZgJafOK4M8jikkSElFQD45zdFtrs63/+/qod+ozhUc +r389qOvuenYhc9pzd7pT4d5lmvQT+104/ZkqzeE+Sq179K9Vrwk6mRdc3fz39zuB0oJLIxha eXSfF5XZ6TjvrmmTDs2tTTUzw92XM1lxZl8IFH/+O6ekQOaf2a+77+q1L9V/zJbk0bmM92D7Z eJ+Ht+IWj+yrzkosxRmJhlrMRcWJAF1GLpNpAgAA X-Env-Sender: jgross@suse.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1480955656!46778424!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40802 invoked from network); 5 Dec 2016 16:34:17 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-12.tower-21.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 5 Dec 2016 16:34:17 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2A84EAAD0; Mon, 5 Dec 2016 16:34:13 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 5 Dec 2016 17:34:09 +0100 Message-Id: <20161205163409.16714-3-jgross@suse.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161205163409.16714-1-jgross@suse.com> References: <20161205163409.16714-1-jgross@suse.com> Cc: Juergen Gross , sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com Subject: [Xen-devel] [PATCH 2/2] xen/x86: add a way to obtain the needed number of memory map entries 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 Today there is no way for a domain to obtain the number of entries of the machine memory map returned by XENMEM_machine_memory_map hypercall. Modify the interface to return just the needed number of map entries in case the buffer was specified as NULL. Signed-off-by: Juergen Gross --- xen/arch/x86/mm.c | 38 +++++++++++++++++++++++--------------- xen/include/public/memory.h | 2 ++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index f8e679d..d384022 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4736,15 +4736,18 @@ static int _handle_iomem_range(unsigned long s, unsigned long e, XEN_GUEST_HANDLE_PARAM(e820entry_t) buffer_param; XEN_GUEST_HANDLE(e820entry_t) buffer; - if ( ctxt->n + 1 >= ctxt->map.nr_entries ) - return -E2BIG; - ent.addr = (uint64_t)ctxt->s << PAGE_SHIFT; - ent.size = (uint64_t)(s - ctxt->s) << PAGE_SHIFT; - ent.type = E820_RESERVED; - buffer_param = guest_handle_cast(ctxt->map.buffer, e820entry_t); - buffer = guest_handle_from_param(buffer_param, e820entry_t); - if ( __copy_to_guest_offset(buffer, ctxt->n, &ent, 1) ) - return -EFAULT; + if ( !guest_handle_is_null(ctxt->map.buffer) ) + { + if ( ctxt->n + 1 >= ctxt->map.nr_entries ) + return -E2BIG; + ent.addr = (uint64_t)ctxt->s << PAGE_SHIFT; + ent.size = (uint64_t)(s - ctxt->s) << PAGE_SHIFT; + ent.type = E820_RESERVED; + buffer_param = guest_handle_cast(ctxt->map.buffer, e820entry_t); + buffer = guest_handle_from_param(buffer_param, e820entry_t); + if ( __copy_to_guest_offset(buffer, ctxt->n, &ent, 1) ) + return -EFAULT; + } ctxt->n++; } ctxt->s = e + 1; @@ -4978,6 +4981,7 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) XEN_GUEST_HANDLE(e820entry_t) buffer; XEN_GUEST_HANDLE_PARAM(e820entry_t) buffer_param; unsigned int i; + bool store; rc = xsm_machine_memory_map(XSM_PRIV); if ( rc ) @@ -4986,9 +4990,10 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) if ( copy_from_guest(&ctxt.map, arg, 1) ) return -EFAULT; + store = !guest_handle_is_null(ctxt.map.buffer); buffer_param = guest_handle_cast(ctxt.map.buffer, e820entry_t); buffer = guest_handle_from_param(buffer_param, e820entry_t); - if ( !guest_handle_okay(buffer, ctxt.map.nr_entries) ) + if ( store && !guest_handle_okay(buffer, ctxt.map.nr_entries) ) return -EFAULT; for ( i = 0, ctxt.n = 0, ctxt.s = 0; i < e820.nr_map; ++i, ++ctxt.n ) @@ -5005,13 +5010,16 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) if ( rc ) break; } - if ( ctxt.map.nr_entries <= ctxt.n + 1 ) + if ( store ) { - rc = -E2BIG; - break; + if ( ctxt.map.nr_entries <= ctxt.n + 1 ) + { + rc = -E2BIG; + break; + } + if ( __copy_to_guest_offset(buffer, ctxt.n, e820.map + i, 1) ) + return -EFAULT; } - if ( __copy_to_guest_offset(buffer, ctxt.n, e820.map + i, 1) ) - return -EFAULT; ctxt.s = PFN_UP(e820.map[i].addr + e820.map[i].size); } diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 20df769..2a61e11 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -341,6 +341,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t); * XENMEM_memory_map. * In case of a buffer not capable to hold all entries of the physical * memory map -E2BIG is returned and the buffer is filled completely. + * Specifying buffer as NULL will return the number of entries required + * to store the complete memory map. * arg == addr of xen_memory_map_t. */ #define XENMEM_machine_memory_map 10