From patchwork Thu Aug 19 17:50:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Costin Lupu X-Patchwork-Id: 12447783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFF0BC432BE for ; Thu, 19 Aug 2021 18:49:27 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 365B461042 for ; Thu, 19 Aug 2021 18:49:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 365B461042 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cs.pub.ro Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.169066.308836 (Exim 4.92) (envelope-from ) id 1mGn6J-0001D3-PI; Thu, 19 Aug 2021 18:49:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 169066.308836; Thu, 19 Aug 2021 18:49:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mGn6J-0001Cw-Lk; Thu, 19 Aug 2021 18:49:15 +0000 Received: by outflank-mailman (input) for mailman id 169066; Thu, 19 Aug 2021 18:49:13 +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.92) (envelope-from ) id 1mGn6H-0000ee-P0 for xen-devel@lists.xenproject.org; Thu, 19 Aug 2021 18:49:13 +0000 Received: from mx.upb.ro (unknown [141.85.13.210]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 21538bc0-011e-11ec-a652-12813bfff9fa; Thu, 19 Aug 2021 18:49:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id AEA1DB5601C0; Thu, 19 Aug 2021 21:49:05 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id vYzLY_UwEol9; Thu, 19 Aug 2021 21:49:03 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 97263B560300; Thu, 19 Aug 2021 21:34:02 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TlMOKk-SEeul; Thu, 19 Aug 2021 21:34:02 +0300 (EEST) Received: from localhost.localdomain (unknown [86.121.144.181]) by mx.upb.ro (Postfix) with ESMTPSA id 7042EB56168B; Thu, 19 Aug 2021 20:50:17 +0300 (EEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 21538bc0-011e-11ec-a652-12813bfff9fa X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v2 1/4] public: Add page related definitions for accessing guests memory Date: Thu, 19 Aug 2021 20:50:09 +0300 Message-Id: <1d9338102d2013addfabc0cf9275ef156fd5080f.1629395092.git.costin.lupu@cs.pub.ro> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 These changes introduce the page related definitions needed for mapping and accessing guests memory. These values are intended to be used by any toolstack component that needs to map guests memory. Until now, the values were defined by the xenctrl.h header, therefore whenever a component had to use them it also had to add a dependency for the xenctrl library. This patch also introduces xen_mk_long() macrodefinition for defining long constants both for C and assembler code. Signed-off-by: Costin Lupu --- xen/include/public/page.h | 36 ++++++++++++++++++++++++++++++++++++ xen/include/public/xen.h | 3 +++ 2 files changed, 39 insertions(+) create mode 100644 xen/include/public/page.h diff --git a/xen/include/public/page.h b/xen/include/public/page.h new file mode 100644 index 0000000000..6b06259bad --- /dev/null +++ b/xen/include/public/page.h @@ -0,0 +1,36 @@ +/****************************************************************************** + * page.h + * + * Page definitions for accessing guests memory + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Copyright (c) 2021, Costin Lupu + */ + +#ifndef __XEN_PUBLIC_PAGE_H__ +#define __XEN_PUBLIC_PAGE_H__ + +#include "xen.h" + +#define XEN_PAGE_SHIFT 12 +#define XEN_PAGE_SIZE (xen_mk_long(1) << XEN_PAGE_SHIFT) +#define XEN_PAGE_MASK (~(XEN_PAGE_SIZE - 1)) + +#endif /* __XEN_PUBLIC_PAGE_H__ */ diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index e373592c33..12531c02b5 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -64,11 +64,13 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); /* Turn a plain number into a C unsigned (long (long)) constant. */ #define __xen_mk_uint(x) x ## U +#define __xen_mk_long(x) x ## L #define __xen_mk_ulong(x) x ## UL #ifndef __xen_mk_ullong # define __xen_mk_ullong(x) x ## ULL #endif #define xen_mk_uint(x) __xen_mk_uint(x) +#define xen_mk_long(x) __xen_mk_long(x) #define xen_mk_ulong(x) __xen_mk_ulong(x) #define xen_mk_ullong(x) __xen_mk_ullong(x) @@ -76,6 +78,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); /* In assembly code we cannot use C numeric constant suffixes. */ #define xen_mk_uint(x) x +#define xen_mk_long(x) x #define xen_mk_ulong(x) x #define xen_mk_ullong(x) x From patchwork Thu Aug 19 17:50:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Costin Lupu X-Patchwork-Id: 12447781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFEDEC4338F for ; Thu, 19 Aug 2021 18:49:27 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5B577610A0 for ; Thu, 19 Aug 2021 18:49:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5B577610A0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cs.pub.ro Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.169065.308826 (Exim 4.92) (envelope-from ) id 1mGn6F-0000uz-HH; Thu, 19 Aug 2021 18:49:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 169065.308826; Thu, 19 Aug 2021 18:49:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mGn6F-0000us-Do; Thu, 19 Aug 2021 18:49:11 +0000 Received: by outflank-mailman (input) for mailman id 169065; Thu, 19 Aug 2021 18:49:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mGn6D-0000ek-W7 for xen-devel@lists.xenproject.org; Thu, 19 Aug 2021 18:49:10 +0000 Received: from mx.upb.ro (unknown [141.85.13.220]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ec046c42-f40c-4421-ab0f-9ede3a08fa76; Thu, 19 Aug 2021 18:49:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 4B2D5B5601C1; Thu, 19 Aug 2021 21:49:07 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id h5aI7n1J83Tp; Thu, 19 Aug 2021 21:49:05 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id C5F2AB56023C; Thu, 19 Aug 2021 21:34:02 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jZuGbMaUYKKK; Thu, 19 Aug 2021 21:34:02 +0300 (EEST) Received: from localhost.localdomain (unknown [86.121.144.181]) by mx.upb.ro (Postfix) with ESMTPSA id 5AC46B5609E2; Thu, 19 Aug 2021 20:50:18 +0300 (EEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ec046c42-f40c-4421-ab0f-9ede3a08fa76 X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu , Juergen Gross , Julien Grall Subject: [PATCH v2 2/4] libs/ctrl: Use Xen values for XC_PAGE_* definitions Date: Thu, 19 Aug 2021 20:50:10 +0300 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 We use the values provided by the Xen public interface for defining the XC_PAGE_* macros. Signed-off-by: Costin Lupu --- tools/include/xenctrl.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index b77726eab7..2031308458 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -54,10 +54,11 @@ #include #include #endif +#include -#define XC_PAGE_SHIFT 12 -#define XC_PAGE_SIZE (1UL << XC_PAGE_SHIFT) -#define XC_PAGE_MASK (~(XC_PAGE_SIZE-1)) +#define XC_PAGE_SHIFT XEN_PAGE_SHIFT +#define XC_PAGE_SIZE XEN_PAGE_SIZE +#define XC_PAGE_MASK XEN_PAGE_MASK #define INVALID_MFN (~0UL) From patchwork Thu Aug 19 17:50:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Costin Lupu X-Patchwork-Id: 12447787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12FC3C43214 for ; Thu, 19 Aug 2021 18:49:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C45EC610A0 for ; Thu, 19 Aug 2021 18:49:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C45EC610A0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cs.pub.ro Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.169068.308844 (Exim 4.92) (envelope-from ) id 1mGn6K-0001G1-65; Thu, 19 Aug 2021 18:49:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 169068.308844; Thu, 19 Aug 2021 18:49:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mGn6J-0001FV-Vj; Thu, 19 Aug 2021 18:49:15 +0000 Received: by outflank-mailman (input) for mailman id 169068; Thu, 19 Aug 2021 18:49:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mGn6I-0000ek-T1 for xen-devel@lists.xenproject.org; Thu, 19 Aug 2021 18:49:14 +0000 Received: from mx.upb.ro (unknown [141.85.13.241]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cfe5d167-636d-41b5-a7fe-268f994a9a36; Thu, 19 Aug 2021 18:49:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id C1814B56023C; Thu, 19 Aug 2021 21:49:07 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id FGm_kwtX8q1b; Thu, 19 Aug 2021 21:49:04 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id E5533B5603CA; Thu, 19 Aug 2021 21:34:02 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id RsFPXnemgUID; Thu, 19 Aug 2021 21:34:02 +0300 (EEST) Received: from localhost.localdomain (unknown [86.121.144.181]) by mx.upb.ro (Postfix) with ESMTPSA id DFD9BB56051E; Thu, 19 Aug 2021 20:50:18 +0300 (EEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cfe5d167-636d-41b5-a7fe-268f994a9a36 X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu , Juergen Gross , Julien Grall Subject: [PATCH v2 3/4] libs/foreignmemory: Use XEN_PAGE_* definitions Date: Thu, 19 Aug 2021 20:50:11 +0300 Message-Id: <6af59839b82b3026afac7228d2d63f786943b445.1629395092.git.costin.lupu@cs.pub.ro> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 These changes refine the changes in 0dbb4be7 which added a dependency to xenctrl library. We use the XEN_PAGE_* definitions instead of the XC_PAGE_* definitions and therefore we get rid of the unnecessary dependency. Signed-off-by: Costin Lupu --- tools/libs/foreignmemory/core.c | 2 +- tools/libs/foreignmemory/freebsd.c | 10 +++++----- tools/libs/foreignmemory/linux.c | 18 +++++++++--------- tools/libs/foreignmemory/minios.c | 10 +--------- tools/libs/foreignmemory/netbsd.c | 10 +++++----- tools/libs/foreignmemory/private.h | 2 +- tools/libs/foreignmemory/solaris.c | 6 +++--- 7 files changed, 25 insertions(+), 33 deletions(-) diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/core.c index 7edc6f0dbf..ad1ad9fc67 100644 --- a/tools/libs/foreignmemory/core.c +++ b/tools/libs/foreignmemory/core.c @@ -202,7 +202,7 @@ int xenforeignmemory_resource_size( if ( rc ) return rc; - *size = fres.nr_frames << XC_PAGE_SHIFT; + *size = fres.nr_frames << XEN_PAGE_SHIFT; return 0; } diff --git a/tools/libs/foreignmemory/freebsd.c b/tools/libs/foreignmemory/freebsd.c index 2cf0fa1c38..9439c4ca6a 100644 --- a/tools/libs/foreignmemory/freebsd.c +++ b/tools/libs/foreignmemory/freebsd.c @@ -63,7 +63,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, privcmd_mmapbatch_t ioctlx; int rc; - addr = mmap(addr, num << XC_PAGE_SHIFT, prot, flags | MAP_SHARED, fd, 0); + addr = mmap(addr, num << XEN_PAGE_SHIFT, prot, flags | MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) return NULL; @@ -78,7 +78,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, { int saved_errno = errno; - (void)munmap(addr, num << XC_PAGE_SHIFT); + (void)munmap(addr, num << XEN_PAGE_SHIFT); errno = saved_errno; return NULL; } @@ -89,7 +89,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { - return munmap(addr, num << XC_PAGE_SHIFT); + return munmap(addr, num << XEN_PAGE_SHIFT); } int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, @@ -101,7 +101,7 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, int osdep_xenforeignmemory_unmap_resource(xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres) { - return fres ? munmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT) : 0; + return fres ? munmap(fres->addr, fres->nr_frames << XEN_PAGE_SHIFT) : 0; } int osdep_xenforeignmemory_map_resource(xenforeignmemory_handle *fmem, @@ -120,7 +120,7 @@ int osdep_xenforeignmemory_map_resource(xenforeignmemory_handle *fmem, /* Request for resource size. Skip mmap(). */ goto skip_mmap; - fres->addr = mmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT, + fres->addr = mmap(fres->addr, fres->nr_frames << XEN_PAGE_SHIFT, fres->prot, fres->flags | MAP_SHARED, fmem->fd, 0); if ( fres->addr == MAP_FAILED ) return -1; diff --git a/tools/libs/foreignmemory/linux.c b/tools/libs/foreignmemory/linux.c index 9062117407..9dabf28cae 100644 --- a/tools/libs/foreignmemory/linux.c +++ b/tools/libs/foreignmemory/linux.c @@ -134,7 +134,7 @@ static int retry_paged(int fd, uint32_t dom, void *addr, /* At least one gfn is still in paging state */ ioctlx.num = 1; ioctlx.dom = dom; - ioctlx.addr = (unsigned long)addr + (i<addr, fres->nr_frames << XC_PAGE_SHIFT) : 0; + return fres ? munmap(fres->addr, fres->nr_frames << XEN_PAGE_SHIFT) : 0; } int osdep_xenforeignmemory_map_resource( @@ -313,7 +313,7 @@ int osdep_xenforeignmemory_map_resource( /* Request for resource size. Skip mmap(). */ goto skip_mmap; - fres->addr = mmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT, + fres->addr = mmap(fres->addr, fres->nr_frames << XEN_PAGE_SHIFT, fres->prot, fres->flags | MAP_SHARED, fmem->fd, 0); if ( fres->addr == MAP_FAILED ) return -1; diff --git a/tools/libs/foreignmemory/minios.c b/tools/libs/foreignmemory/minios.c index f2f4dfb2be..2454eb9af3 100644 --- a/tools/libs/foreignmemory/minios.c +++ b/tools/libs/foreignmemory/minios.c @@ -17,14 +17,6 @@ * Copyright 2007-2008 Samuel Thibault . */ -/* - * xenctrl.h currently defines __XEN_TOOLS__ which affects what is - * exposed by Xen headers. As the define needs to be set consistently, - * we want to include xenctrl.h before the mini-os headers (they include - * public headers). - */ -#include - #include #include #include @@ -63,7 +55,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { - return munmap(addr, num << XC_PAGE_SHIFT); + return munmap(addr, num << XEN_PAGE_SHIFT); } /* diff --git a/tools/libs/foreignmemory/netbsd.c b/tools/libs/foreignmemory/netbsd.c index 597db775d7..ba69b9c6bb 100644 --- a/tools/libs/foreignmemory/netbsd.c +++ b/tools/libs/foreignmemory/netbsd.c @@ -76,7 +76,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, { int fd = fmem->fd; privcmd_mmapbatch_v2_t ioctlx; - addr = mmap(addr, num * XC_PAGE_SIZE, prot, + addr = mmap(addr, num * XEN_PAGE_SIZE, prot, flags | MAP_ANON | MAP_SHARED, -1, 0); if ( addr == MAP_FAILED ) { PERROR("osdep_xenforeignmemory_map: mmap failed"); @@ -93,7 +93,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, { int saved_errno = errno; PERROR("osdep_xenforeignmemory_map: ioctl failed"); - munmap(addr, num * XC_PAGE_SIZE); + munmap(addr, num * XEN_PAGE_SIZE); errno = saved_errno; return NULL; } @@ -104,7 +104,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { - return munmap(addr, num * XC_PAGE_SIZE); + return munmap(addr, num * XEN_PAGE_SIZE); } int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, @@ -117,7 +117,7 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, int osdep_xenforeignmemory_unmap_resource( xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres) { - return fres ? munmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT) : 0; + return fres ? munmap(fres->addr, fres->nr_frames << XEN_PAGE_SHIFT) : 0; } int osdep_xenforeignmemory_map_resource( @@ -136,7 +136,7 @@ int osdep_xenforeignmemory_map_resource( /* Request for resource size. Skip mmap(). */ goto skip_mmap; - fres->addr = mmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT, + fres->addr = mmap(fres->addr, fres->nr_frames << XEN_PAGE_SHIFT, fres->prot, fres->flags | MAP_ANON | MAP_SHARED, -1, 0); if ( fres->addr == MAP_FAILED ) return -1; diff --git a/tools/libs/foreignmemory/private.h b/tools/libs/foreignmemory/private.h index 8540303adc..1200f98067 100644 --- a/tools/libs/foreignmemory/private.h +++ b/tools/libs/foreignmemory/private.h @@ -1,7 +1,6 @@ #ifndef XENFOREIGNMEMORY_PRIVATE_H #define XENFOREIGNMEMORY_PRIVATE_H -#include #include #include @@ -9,6 +8,7 @@ #include #include +#include #include struct xenforeignmemory_handle { diff --git a/tools/libs/foreignmemory/solaris.c b/tools/libs/foreignmemory/solaris.c index 958fb01f6d..4466780bd8 100644 --- a/tools/libs/foreignmemory/solaris.c +++ b/tools/libs/foreignmemory/solaris.c @@ -72,7 +72,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, { int fd = fmem->fd; privcmd_mmapbatch_t ioctlx; - addr = mmap(addr, num*XC_PAGE_SIZE, prot, flags | MAP_SHARED, fd, 0); + addr = mmap(addr, num*XEN_PAGE_SIZE, prot, flags | MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) return NULL; @@ -84,7 +84,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, { int saved_errno = errno; - (void)munmap(addr, num*XC_PAGE_SIZE); + (void)munmap(addr, num*XEN_PAGE_SIZE); errno = saved_errno; return NULL; } @@ -94,7 +94,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { - return munmap(addr, num*XC_PAGE_SIZE); + return munmap(addr, num*XEN_PAGE_SIZE); } /* From patchwork Thu Aug 19 17:50:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Costin Lupu X-Patchwork-Id: 12447789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84E32C4338F for ; Thu, 19 Aug 2021 18:49:30 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5330261042 for ; Thu, 19 Aug 2021 18:49:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5330261042 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cs.pub.ro Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.169069.308862 (Exim 4.92) (envelope-from ) id 1mGn6O-0001q0-Ev; Thu, 19 Aug 2021 18:49:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 169069.308862; Thu, 19 Aug 2021 18:49:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mGn6O-0001pr-A9; Thu, 19 Aug 2021 18:49:20 +0000 Received: by outflank-mailman (input) for mailman id 169069; Thu, 19 Aug 2021 18:49:18 +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.92) (envelope-from ) id 1mGn6M-0000ee-P5 for xen-devel@lists.xenproject.org; Thu, 19 Aug 2021 18:49:18 +0000 Received: from mx.upb.ro (unknown [141.85.13.210]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 25a7411c-011e-11ec-a652-12813bfff9fa; Thu, 19 Aug 2021 18:49:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 10381B560115; Thu, 19 Aug 2021 21:49:12 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Gl-SHzGYgl4m; Thu, 19 Aug 2021 21:49:06 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 4205BB560448; Thu, 19 Aug 2021 21:34:03 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 4Xhq7L00DpiX; Thu, 19 Aug 2021 21:34:03 +0300 (EEST) Received: from localhost.localdomain (unknown [86.121.144.181]) by mx.upb.ro (Postfix) with ESMTPSA id 6E154B56053B; Thu, 19 Aug 2021 20:50:19 +0300 (EEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 25a7411c-011e-11ec-a652-12813bfff9fa X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu , Juergen Gross , Julien Grall Subject: [PATCH v2 4/4] libs/gnttab: Use XEN_PAGE_* definitions Date: Thu, 19 Aug 2021 20:50:12 +0300 Message-Id: <1b78b6e4a196a7f57d014ee699f4e8080b60610a.1629395092.git.costin.lupu@cs.pub.ro> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 These changes refine the changes in d1b32abd which added a dependency to xenctrl library. We use the XEN_PAGE_* definitions instead of the XC_PAGE_* definitions and therefore we get rid of the unnecessary dependency. Signed-off-by: Costin Lupu --- tools/libs/gnttab/freebsd.c | 20 ++++++++++---------- tools/libs/gnttab/linux.c | 20 ++++++++++---------- tools/libs/gnttab/netbsd.c | 20 ++++++++++---------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tools/libs/gnttab/freebsd.c b/tools/libs/gnttab/freebsd.c index e42ac3fbf3..7ecb0e3b38 100644 --- a/tools/libs/gnttab/freebsd.c +++ b/tools/libs/gnttab/freebsd.c @@ -28,9 +28,9 @@ #include #include +#include #include -#include #include #include "private.h" @@ -74,7 +74,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, int domids_stride; unsigned int refs_size = ROUNDUP(count * sizeof(struct ioctl_gntdev_grant_ref), - XC_PAGE_SHIFT); + XEN_PAGE_SHIFT); int os_page_size = getpagesize(); domids_stride = (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN) ? 0 : 1; @@ -105,7 +105,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, goto out; } - addr = mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd, + addr = mmap(NULL, XEN_PAGE_SIZE * count, prot, MAP_SHARED, fd, map.index); if ( addr != MAP_FAILED ) { @@ -114,7 +114,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, notify.index = map.index; notify.action = 0; - if ( notify_offset < XC_PAGE_SIZE * count ) + if ( notify_offset < XEN_PAGE_SIZE * count ) { notify.index += notify_offset; notify.action |= UNMAP_NOTIFY_CLEAR_BYTE; @@ -129,7 +129,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, if ( rv ) { GTERROR(xgt->logger, "ioctl SET_UNMAP_NOTIFY failed"); - munmap(addr, count * XC_PAGE_SIZE); + munmap(addr, count * XEN_PAGE_SIZE); addr = MAP_FAILED; } } @@ -187,7 +187,7 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, } /* Next, unmap the memory. */ - if ( (rc = munmap(start_address, count * XC_PAGE_SIZE)) ) + if ( (rc = munmap(start_address, count * XEN_PAGE_SIZE)) ) return rc; /* Finally, unmap the driver slots used to store the grant information. */ @@ -254,7 +254,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, goto out; } - area = mmap(NULL, count * XC_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + area = mmap(NULL, count * XEN_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gref_info.index); if ( area == MAP_FAILED ) @@ -266,7 +266,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, notify.index = gref_info.index; notify.action = 0; - if ( notify_offset < XC_PAGE_SIZE * count ) + if ( notify_offset < XEN_PAGE_SIZE * count ) { notify.index += notify_offset; notify.action |= UNMAP_NOTIFY_CLEAR_BYTE; @@ -281,7 +281,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, if ( err ) { GSERROR(xgs->logger, "ioctl SET_UNMAP_NOTIFY failed"); - munmap(area, count * XC_PAGE_SIZE); + munmap(area, count * XEN_PAGE_SIZE); area = NULL; } @@ -304,7 +304,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, int osdep_gntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count) { - return munmap(start_address, count * XC_PAGE_SIZE); + return munmap(start_address, count * XEN_PAGE_SIZE); } /* diff --git a/tools/libs/gnttab/linux.c b/tools/libs/gnttab/linux.c index 5628fd5719..11f1acb771 100644 --- a/tools/libs/gnttab/linux.c +++ b/tools/libs/gnttab/linux.c @@ -29,10 +29,10 @@ #include #include +#include #include #include -#include #include #include "private.h" @@ -101,7 +101,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, map = alloca(map_size); else { - map_size = ROUNDUP(map_size, XC_PAGE_SHIFT); + map_size = ROUNDUP(map_size, XEN_PAGE_SHIFT); map = mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0); if ( map == MAP_FAILED ) @@ -125,7 +125,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, } retry: - addr = mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd, + addr = mmap(NULL, XEN_PAGE_SIZE * count, prot, MAP_SHARED, fd, map->index); if (addr == MAP_FAILED && errno == EAGAIN) @@ -150,7 +150,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, struct ioctl_gntdev_unmap_notify notify; notify.index = map->index; notify.action = 0; - if (notify_offset < XC_PAGE_SIZE * count) { + if (notify_offset < XEN_PAGE_SIZE * count) { notify.index += notify_offset; notify.action |= UNMAP_NOTIFY_CLEAR_BYTE; } @@ -162,7 +162,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, rv = ioctl(fd, IOCTL_GNTDEV_SET_UNMAP_NOTIFY, ¬ify); if (rv) { GTERROR(xgt->logger, "ioctl SET_UNMAP_NOTIFY failed"); - munmap(addr, count * XC_PAGE_SIZE); + munmap(addr, count * XEN_PAGE_SIZE); addr = MAP_FAILED; } } @@ -218,7 +218,7 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, } /* Next, unmap the memory. */ - if ( (rc = munmap(start_address, count * XC_PAGE_SIZE)) ) + if ( (rc = munmap(start_address, count * XEN_PAGE_SIZE)) ) return rc; /* Finally, unmap the driver slots used to store the grant information. */ @@ -464,7 +464,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, goto out; } - area = mmap(NULL, count * XC_PAGE_SIZE, PROT_READ | PROT_WRITE, + area = mmap(NULL, count * XEN_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gref_info->index); if (area == MAP_FAILED) { @@ -475,7 +475,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, notify.index = gref_info->index; notify.action = 0; - if (notify_offset < XC_PAGE_SIZE * count) { + if (notify_offset < XEN_PAGE_SIZE * count) { notify.index += notify_offset; notify.action |= UNMAP_NOTIFY_CLEAR_BYTE; } @@ -487,7 +487,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, err = ioctl(fd, IOCTL_GNTALLOC_SET_UNMAP_NOTIFY, ¬ify); if (err) { GSERROR(xgs->logger, "ioctl SET_UNMAP_NOTIFY failed"); - munmap(area, count * XC_PAGE_SIZE); + munmap(area, count * XEN_PAGE_SIZE); area = NULL; } @@ -508,7 +508,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, int osdep_gntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count) { - return munmap(start_address, count * XC_PAGE_SIZE); + return munmap(start_address, count * XEN_PAGE_SIZE); } /* diff --git a/tools/libs/gnttab/netbsd.c b/tools/libs/gnttab/netbsd.c index a4ad624b54..beb94be468 100644 --- a/tools/libs/gnttab/netbsd.c +++ b/tools/libs/gnttab/netbsd.c @@ -28,8 +28,8 @@ #include #include -#include #include +#include #include #include "private.h" @@ -84,19 +84,19 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, } map.count = count; - addr = mmap(NULL, count * XC_PAGE_SIZE, + addr = mmap(NULL, count * XEN_PAGE_SIZE, prot, flags | MAP_ANON | MAP_SHARED, -1, 0); if ( map.va == MAP_FAILED ) { GTERROR(xgt->logger, "osdep_gnttab_grant_map: mmap failed"); - munmap((void *)map.va, count * XC_PAGE_SIZE); + munmap((void *)map.va, count * XEN_PAGE_SIZE); addr = MAP_FAILED; } map.va = addr; map.notify.offset = 0; map.notify.action = 0; - if ( notify_offset < XC_PAGE_SIZE * count ) + if ( notify_offset < XEN_PAGE_SIZE * count ) { map.notify.offset = notify_offset; map.notify.action |= UNMAP_NOTIFY_CLEAR_BYTE; @@ -112,7 +112,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, { GTERROR(xgt->logger, "ioctl IOCTL_GNTDEV_MMAP_GRANT_REF failed: %d", rv); - munmap(addr, count * XC_PAGE_SIZE); + munmap(addr, count * XEN_PAGE_SIZE); addr = MAP_FAILED; } @@ -133,7 +133,7 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, } /* Next, unmap the memory. */ - rc = munmap(start_address, count * XC_PAGE_SIZE); + rc = munmap(start_address, count * XEN_PAGE_SIZE); return rc; } @@ -184,7 +184,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, alloc.domid = domid; alloc.flags = writable ? GNTDEV_ALLOC_FLAG_WRITABLE : 0; alloc.count = count; - area = mmap(NULL, count * XC_PAGE_SIZE, + area = mmap(NULL, count * XEN_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); if ( area == MAP_FAILED ) @@ -197,7 +197,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, alloc.notify.offset = 0; alloc.notify.action = 0; - if ( notify_offset < XC_PAGE_SIZE * count ) + if ( notify_offset < XEN_PAGE_SIZE * count ) { alloc.notify.offset = notify_offset; alloc.notify.action |= UNMAP_NOTIFY_CLEAR_BYTE; @@ -212,7 +212,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, if ( err ) { GSERROR(xgs->logger, "IOCTL_GNTDEV_ALLOC_GRANT_REF failed"); - munmap(area, count * XC_PAGE_SIZE); + munmap(area, count * XEN_PAGE_SIZE); area = MAP_FAILED; goto out; } @@ -227,7 +227,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, int osdep_gntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count) { - return munmap(start_address, count * XC_PAGE_SIZE); + return munmap(start_address, count * XEN_PAGE_SIZE); } /*