From patchwork Wed Jun 28 19:27:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Druzhinin X-Patchwork-Id: 9815255 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 5C3BC603F2 for ; Wed, 28 Jun 2017 19:30:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C3E12807B for ; Wed, 28 Jun 2017 19:30:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D35326E39; Wed, 28 Jun 2017 19:30:19 +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 5243E26E39 for ; Wed, 28 Jun 2017 19:30:18 +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 1dQId6-0002Fs-8h; Wed, 28 Jun 2017 19:28:00 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQId4-0002Fi-LL for xen-devel@lists.xen.org; Wed, 28 Jun 2017 19:27:58 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id C9/34-03704-D3304595; Wed, 28 Jun 2017 19:27:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsWyU9JRQteWOST S4NoqYYslHxezODB6HN39mymAMYo1My8pvyKBNePIvo2MBaciKp68mcHSwLjRsYuRk0NCwE/i 0cV2FhCbTcBA4tSmRWC2iICsxOquOexdjFwczAKLGSWmdS5gBUkIAzU8+DsdzGYRUJVY+KaJr YuRg4NXwFOi+ysjxEw5iZvnOplBbF4BQYmTM5+AzWQWkJA4+OIFWFxIQE3iaNcuFoj6NIn2+9 dYJzDyzELSMgtJywJGplWM6sWpRWWpRbqGeklFmekZJbmJmTm6hgZmermpxcWJ6ak5iUnFesn 5uZsYgSHCAAQ7GHc+dzrEKMnBpCTKe+R9cKQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd79jCGR QoJFqempFWmZOcBghUlLcPAoifCu+g7UyltckJhbnJkOkTrFqCglzvsPpE8AJJFRmgfXBouQS 4yyUsK8jECHCPEUpBblZpagyr9iFOdgVBLmNWYAmsKTmVcCN/0V0GImoMUs8wJAFpckIqSkGh i5pRPOs/61Cbd+ZPlNVfvIBSEr/aqdOQciph9NWrVB581N8/Y5y71nrtmkYCs8xeVrSOBn24c Hrl/lVP5bx99aFLyXO8hUeIJet4zD+98bPl5bsnL2qVutQQd23b92X9l6t+Xl44wfjj692mgv 9iO69ebqwz+OndTPLbGOWzLbR+wpwzWf359mKbEUZyQaajEXFScCABO8ysaLAgAA X-Env-Sender: prvs=34541614c=igor.druzhinin@citrix.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1498678077!64115213!1 X-Originating-IP: [185.25.65.24] X-SpamReason: No, hits=0.0 required=7.0 tests=received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42041 invoked from network); 28 Jun 2017 19:27:57 -0000 Received: from smtp.eu.citrix.com (HELO SMTP.EU.CITRIX.COM) (185.25.65.24) by server-14.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jun 2017 19:27:57 -0000 X-IronPort-AV: E=Sophos;i="5.40,277,1496102400"; d="scan'208";a="48555663" From: Igor Druzhinin To: Date: Wed, 28 Jun 2017 20:27:08 +0100 Message-ID: <1498678028-27200-1-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-ClientProxiedBy: FTLPEX02CAS03.citrite.net (10.13.99.94) To AMSPEX02CL03.citrite.net (10.69.22.127) Cc: Igor Druzhinin , Ian Jackson , Wei Liu , Andrew Cooper Subject: [Xen-devel] [PATCH] tools/libxenforeignmemory: add xenforeignmemory_map2 function 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The new function repeats the behavior of the first version except it has an extended list of arguments which are subsequently passed to mmap() call. This is needed for QEMU depriviledging. Signed-off-by: Igor Druzhinin Reviewed-by: Andrew Cooper Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper --- tools/libs/foreignmemory/Makefile | 2 +- tools/libs/foreignmemory/compat.c | 6 +++--- tools/libs/foreignmemory/core.c | 18 +++++++++++++----- tools/libs/foreignmemory/freebsd.c | 7 +++---- tools/libs/foreignmemory/include/xenforeignmemory.h | 12 ++++++++++++ tools/libs/foreignmemory/libxenforeignmemory.map | 4 ++++ tools/libs/foreignmemory/linux.c | 7 +++---- tools/libs/foreignmemory/minios.c | 4 ++-- tools/libs/foreignmemory/netbsd.c | 6 +++--- tools/libs/foreignmemory/private.h | 7 ++++--- tools/libs/foreignmemory/solaris.c | 5 ++--- 11 files changed, 50 insertions(+), 28 deletions(-) diff --git a/tools/libs/foreignmemory/Makefile b/tools/libs/foreignmemory/Makefile index 2f2caa1..5e93ee7 100644 --- a/tools/libs/foreignmemory/Makefile +++ b/tools/libs/foreignmemory/Makefile @@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 -MINOR = 1 +MINOR = 2 SHLIB_LDFLAGS += -Wl,--version-script=libxenforeignmemory.map CFLAGS += -Werror -Wmissing-prototypes diff --git a/tools/libs/foreignmemory/compat.c b/tools/libs/foreignmemory/compat.c index b79ec1a..5f730ca 100644 --- a/tools/libs/foreignmemory/compat.c +++ b/tools/libs/foreignmemory/compat.c @@ -21,8 +21,8 @@ #include "private.h" -void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, - uint32_t dom, int prot, size_t num, +void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom, + void *addr, int prot, int flags, size_t num, const xen_pfn_t arr[/*num*/], int err[/*num*/]) { xen_pfn_t *pfn; @@ -41,7 +41,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, } memcpy(pfn, arr, num * sizeof(*arr)); - ret = osdep_map_foreign_batch(fmem, dom, prot, pfn, num); + ret = osdep_map_foreign_batch(fmem, dom, addr, prot, flags, pfn, num); if (ret) { for (i = 0; i < num; ++i) diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/core.c index 0ebd429..a6897dc 100644 --- a/tools/libs/foreignmemory/core.c +++ b/tools/libs/foreignmemory/core.c @@ -63,10 +63,10 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem) return rc; } -void *xenforeignmemory_map(xenforeignmemory_handle *fmem, - uint32_t dom, int prot, - size_t num, - const xen_pfn_t arr[/*num*/], int err[/*num*/]) +void *xenforeignmemory_map2(xenforeignmemory_handle *fmem, + uint32_t dom, void *addr, + int prot, int flags, size_t num, + const xen_pfn_t arr[/*num*/], int err[/*num*/]) { void *ret; int *err_to_free = NULL; @@ -77,7 +77,7 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, if ( err == NULL ) return NULL; - ret = osdep_xenforeignmemory_map(fmem, dom, prot, num, arr, err); + ret = osdep_xenforeignmemory_map(fmem, dom, addr, prot, flags, num, arr, err); if ( ret && err_to_free ) { @@ -100,6 +100,14 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, return ret; } +void *xenforeignmemory_map(xenforeignmemory_handle *fmem, + uint32_t dom, int prot, + size_t num, + const xen_pfn_t arr[/*num*/], int err[/*num*/]) +{ + return xenforeignmemory_map2(fmem, dom, NULL, prot, 0, num, arr, err); +} + int xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { diff --git a/tools/libs/foreignmemory/freebsd.c b/tools/libs/foreignmemory/freebsd.c index f6cd08c..dec4474 100644 --- a/tools/libs/foreignmemory/freebsd.c +++ b/tools/libs/foreignmemory/freebsd.c @@ -55,16 +55,15 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem) } void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, - uint32_t dom, int prot, - size_t num, + uint32_t dom, void *addr, + int prot, int flags, size_t num, const xen_pfn_t arr[/*num*/], int err[/*num*/]) { int fd = fmem->fd; privcmd_mmapbatch_t ioctlx; - void *addr; int rc; - addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0); + addr = mmap(addr, num << PAGE_SHIFT, prot, flags | MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) { PERROR("xc_map_foreign_bulk: mmap failed"); diff --git a/tools/libs/foreignmemory/include/xenforeignmemory.h b/tools/libs/foreignmemory/include/xenforeignmemory.h index d5be648..a780d14 100644 --- a/tools/libs/foreignmemory/include/xenforeignmemory.h +++ b/tools/libs/foreignmemory/include/xenforeignmemory.h @@ -108,6 +108,18 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom, const xen_pfn_t arr[/*pages*/], int err[/*pages*/]); /* + * Almost like the previous one but also accepts two additional parameters: + * + * @addr is used as a hint address for foreign map placement (see mmap(2)). + * @flags is a set of additional flags as for mmap(2). Not all of the flag + * combinations are possible due to implementation details on different + * platforms. + */ +void *xenforeignmemory_map2(xenforeignmemory_handle *fmem, uint32_t dom, + void *addr, int prot, int flags, size_t pages, + const xen_pfn_t arr[/*pages*/], int err[/*pages*/]); + +/* * Unmap a mapping previous created with xenforeignmemory_map(). * * Returns 0 on success on failure sets errno and returns -1. diff --git a/tools/libs/foreignmemory/libxenforeignmemory.map b/tools/libs/foreignmemory/libxenforeignmemory.map index 41a8899..716ecaf 100644 --- a/tools/libs/foreignmemory/libxenforeignmemory.map +++ b/tools/libs/foreignmemory/libxenforeignmemory.map @@ -10,3 +10,7 @@ VERS_1.1 { global: xenforeignmemory_restrict; } VERS_1.0; +VERS_1.2 { + global: + xenforeignmemory_map2; +} VERS_1.1; diff --git a/tools/libs/foreignmemory/linux.c b/tools/libs/foreignmemory/linux.c index 320bb21..374e45a 100644 --- a/tools/libs/foreignmemory/linux.c +++ b/tools/libs/foreignmemory/linux.c @@ -142,17 +142,16 @@ out: } void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, - uint32_t dom, int prot, - size_t num, + uint32_t dom, void *addr, + int prot, int flags, size_t num, const xen_pfn_t arr[/*num*/], int err[/*num*/]) { int fd = fmem->fd; privcmd_mmapbatch_v2_t ioctlx; - void *addr; size_t i; int rc; - addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, + addr = mmap(addr, num << PAGE_SHIFT, prot, flags | MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) { diff --git a/tools/libs/foreignmemory/minios.c b/tools/libs/foreignmemory/minios.c index 2dd4910..75f3401 100644 --- a/tools/libs/foreignmemory/minios.c +++ b/tools/libs/foreignmemory/minios.c @@ -40,8 +40,8 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem) } void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, - uint32_t dom, int prot, - size_t num, + uint32_t dom, void *addr, + int prot, int flags, size_t num, const xen_pfn_t arr[/*num*/], int err[/*num*/]) { unsigned long pt_prot = 0; diff --git a/tools/libs/foreignmemory/netbsd.c b/tools/libs/foreignmemory/netbsd.c index af3a1a4..9bf95ef 100644 --- a/tools/libs/foreignmemory/netbsd.c +++ b/tools/libs/foreignmemory/netbsd.c @@ -67,12 +67,12 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem) } void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, - int prot, xen_pfn_t *arr, int num) + void *addr, int prot, int flags, + xen_pfn_t *arr, int num) { int fd = fmem->fd; privcmd_mmapbatch_t ioctlx; - void *addr; - addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0); + addr = mmap(addr, num*XC_PAGE_SIZE, prot, flags | MAP_ANON | MAP_SHARED, -1, 0); if ( addr == MAP_FAILED ) { PERROR("osdep_map_foreign_batch: mmap failed"); return NULL; diff --git a/tools/libs/foreignmemory/private.h b/tools/libs/foreignmemory/private.h index ed7ec7a..c5c07cc 100644 --- a/tools/libs/foreignmemory/private.h +++ b/tools/libs/foreignmemory/private.h @@ -26,8 +26,8 @@ int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem); int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem); void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, - uint32_t dom, int prot, - size_t num, + uint32_t dom, void *addr, + int prot, int flags, size_t num, const xen_pfn_t arr[num], int err[num]); int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num); @@ -38,7 +38,8 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, #if defined(__NetBSD__) || defined(__sun__) /* Strictly compat for those two only only */ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom, - int prot, xen_pfn_t *arr, int num); + void *addr, int prot, int flags, + xen_pfn_t *arr, int num); #endif #define PERROR(_f...) \ diff --git a/tools/libs/foreignmemory/solaris.c b/tools/libs/foreignmemory/solaris.c index fe7bb45..a33decb 100644 --- a/tools/libs/foreignmemory/solaris.c +++ b/tools/libs/foreignmemory/solaris.c @@ -68,12 +68,11 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem) } void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, - int prot, xen_pfn_t *arr, int num) + void *addr, int prot, int flags, xen_pfn_t *arr, int num) { int fd = fmem->fd; privcmd_mmapbatch_t ioctlx; - void *addr; - addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_SHARED, fd, 0); + addr = mmap(addr, num*XC_PAGE_SIZE, prot, flags | MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) return NULL;