From patchwork Thu Mar 24 20:00:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 8664451 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 797799F326 for ; Thu, 24 Mar 2016 20:04:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 92E9E2037E for ; Thu, 24 Mar 2016 20:04:42 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 3615B201F5 for ; Thu, 24 Mar 2016 20:04:41 +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 1ajBSk-0000Y4-J2; Thu, 24 Mar 2016 20:02:34 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajBSj-0000VX-2B for xen-devel@lists.xenproject.org; Thu, 24 Mar 2016 20:02:33 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 3B/A0-07120-8D744F65; Thu, 24 Mar 2016 20:02:32 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1458849750!5902886!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55813 invoked from network); 24 Mar 2016 20:02:31 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-7.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 24 Mar 2016 20:02:31 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u2OK15lG015241 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 Mar 2016 20:01:05 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u2OK15bT013652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 Mar 2016 20:01:05 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u2OK14sd014957; Thu, 24 Mar 2016 20:01:04 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Mar 2016 13:01:04 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id CA0BF6A00D1; Thu, 24 Mar 2016 16:01:02 -0400 (EDT) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, konrad@kernel.org, andrew.cooper3@citrix.com, mpohlack@amazon.de, sasha.levin@oracle.com Date: Thu, 24 Mar 2016 16:00:16 -0400 Message-Id: <1458849640-22588-5-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1458849640-22588-1-git-send-email-konrad.wilk@oracle.com> References: <1458849640-22588-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: Keir Fraser , Tim Deegan , Ian Jackson , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v5 04/28] vmap: Add vmalloc_cb and vfree_cb 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For those users who want to supply their own vmap callback. To be called _after_ the pages have been allocated and the vmap API is ready to hand out virtual addresses. Instead of using the vmap ones it can call the callback which will be responsible for generating the virtual address. This allows users (such as xSplice) to provide their own mechanism to set the page flags. The users (such as patch titled "xsplice: Implement payload loading") can wrap the calls to __vmap to accomplish this. We also provide a mechanism for the calleer to squirrel the MFN array in case they want to modify the virtual addresses easily. We also provide the free-ing code path - to use the vunmap_cb to take care of tearing down the virtual addresses. Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Ian Jackson Cc: Jan Beulich Cc: Keir Fraser Cc: Tim Deegan v4: New patch. v5: Update per Jan's comments. --- --- xen/common/vmap.c | 33 ++++++++++++++++++++++++++------- xen/include/xen/vmap.h | 14 ++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/xen/common/vmap.c b/xen/common/vmap.c index 134eda0..08e7859 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -216,7 +216,7 @@ void vunmap(const void *va) vm_free(va); } -void *vmalloc(size_t size) +void *vmalloc_cb(size_t size, vmap_cb_t *vmap_cb, mfn_t **mfn_array) { mfn_t *mfn; size_t pages, i; @@ -238,11 +238,15 @@ void *vmalloc(size_t size) mfn[i] = _mfn(page_to_mfn(pg)); } - va = vmap(mfn, pages); + va = vmap_cb ? vmap_cb(mfn, pages) : vmap(mfn, pages); if ( va == NULL ) goto error; - xfree(mfn); + if ( mfn_array ) + *mfn_array = mfn; + else + xfree(mfn); + return va; error: @@ -252,6 +256,11 @@ void *vmalloc(size_t size) return NULL; } +void *vmalloc(size_t size) +{ + return vmalloc_cb(size, NULL, NULL); +} + void *vzalloc(size_t size) { void *p = vmalloc(size); @@ -266,16 +275,15 @@ void *vzalloc(size_t size) return p; } -void vfree(void *va) +void vfree_cb(void *va, unsigned int pages, vfree_cb_t *vfree_cb_fnc) { - unsigned int i, pages; + unsigned int i; struct page_info *pg; PAGE_LIST_HEAD(pg_list); if ( !va ) return; - pages = vm_size(va); ASSERT(pages); for ( i = 0; i < pages; i++ ) @@ -285,9 +293,20 @@ void vfree(void *va) ASSERT(page); page_list_add(page, &pg_list); } - vunmap(va); + if ( !vfree_cb_fnc ) + vunmap(va); + else + vfree_cb_fnc(va, pages); while ( (pg = page_list_remove_head(&pg_list)) != NULL ) free_domheap_page(pg); } + +void vfree(void *va) +{ + if ( !va ) + return; + + vfree_cb(va, vm_size(va), NULL); +} #endif diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h index 5671ac8..02cadb3 100644 --- a/xen/include/xen/vmap.h +++ b/xen/include/xen/vmap.h @@ -12,9 +12,23 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity, void *vmap(const mfn_t *mfn, unsigned int nr); void vunmap(const void *); void *vmalloc(size_t size); + +/* + * Callback for vmalloc_cb to use when vmap-ing. + */ +typedef void *(vmap_cb_t)(const mfn_t *mfn, unsigned int pages); +void *vmalloc_cb(size_t size, vmap_cb_t *vmap_cb, mfn_t **); + void *vzalloc(size_t size); void vfree(void *va); +/* + * Callback for vfree to use an equivalent of vmap_cb_t + * when tearing down. + */ +typedef void (vfree_cb_t)(void *va, unsigned int pages); +void vfree_cb(void *va, unsigned int pages, vfree_cb_t *vfree_cb_fnc); + void __iomem *ioremap(paddr_t, size_t); static inline void iounmap(void __iomem *va)