From patchwork Thu Apr 27 14:35:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9702979 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 AA445601D3 for ; Thu, 27 Apr 2017 14:42:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9462F28645 for ; Thu, 27 Apr 2017 14:42:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 893792865A; Thu, 27 Apr 2017 14:42:55 +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 1CC2C28655 for ; Thu, 27 Apr 2017 14:42:55 +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 1d3kbF-0002Zj-I3; Thu, 27 Apr 2017 14:40:53 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3kbE-0002ZU-FZ for xen-devel@lists.xenproject.org; Thu, 27 Apr 2017 14:40:52 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id F7/21-01733-3F202095; Thu, 27 Apr 2017 14:40:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLIsWRWlGSWpSXmKPExsXitHRDpO5HJqZ IgwMvRSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozLm/4zF6yUqWiZcYmpgXG9SBcjJ4eEgL/E zS/XmEFsNgEdiYtzd7J1MXJwiAioSNzea9DFyMXBLHCCUaJ91RY2kBphgQiJR3s2sYDYLAKqE p+fzAezeQUsJa48vcYKMVNP4u3EF4wgNqeAlcS715fBbCGgmslzHzJB1AtKnJz5BKyXWUBTon X7b3YIW16ieetsZoh6RYn+eQ/YJjDyzULSMgtJyywkLQsYmVcxahSnFpWlFukaWuglFWWmZ5T kJmbm6BoamOrlphYXJ6an5iQmFesl5+duYgQGGwMQ7GBs2u55iFGSg0lJlFf2IGOkEF9Sfkpl RmJxRnxRaU5q8SFGGQ4OJQneIkamSCHBotT01Iq0zBxg2MOkJTh4lER4BYChL8RbXJCYW5yZD pE6xagoJc57FKRPACSRUZoH1waLtUuMslLCvIxAhwjxFKQW5WaWoMq/YhTnYFQS5l0GMoUnM6 8EbvoroMVMQItZXBhAFpckIqSkGhjDyp5tf/sn7enCXUpG2ZeMizbqcRU03lyQ7sVxvJ4v7c2 n9kvdevzxXeEBPzPFApMacj/fWaAvVT9Tao/s43uC1cXeFSsbuYz9Gis+Lqgv0Pr9Zm+JbHbE p2gBK9n1z2YaTL7sm/jwU3RlRc2Z+y80b4Zt3Oy2KctrycLdXR4VxlkenU4LJJVYijMSDbWYi 4oTAbUxmWqwAgAA X-Env-Sender: prvs=283fe5697=roger.pau@citrix.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1493304045!74066345!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33693 invoked from network); 27 Apr 2017 14:40:48 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-10.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 27 Apr 2017 14:40:48 -0000 X-IronPort-AV: E=Sophos;i="5.37,384,1488844800"; d="scan'208";a="421307941" From: Roger Pau Monne To: Date: Thu, 27 Apr 2017 15:35:40 +0100 Message-ID: <20170427143546.14662-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) In-Reply-To: <20170427143546.14662-1-roger.pau@citrix.com> References: <20170427143546.14662-1-roger.pau@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , julien.grall@arm.com, Jan Beulich , boris.ostrovsky@oracle.com, Roger Pau Monne Subject: [Xen-devel] [PATCH v3 3/9] xen/mm: move modify_identity_mmio to global file and drop __init 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 And also allow it to do non-identity mappings by adding a new parameter. This function will be needed in other parts apart from PVH Dom0 build. While there fix the function to use gfn_t and mfn_t instead of unsigned long for memory addresses. Signed-off-by: Roger Pau Monné --- Cc: Jan Beulich Cc: Andrew Cooper --- Changes since v2: - Use mfn_t and gfn_t. - Remove stray newline. --- xen/arch/x86/hvm/dom0_build.c | 22 +--------------------- xen/common/memory.c | 36 ++++++++++++++++++++++++++++++++++++ xen/include/xen/p2m-common.h | 3 +++ 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index b8999a053a..9efe4e571b 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -64,27 +64,7 @@ static struct acpi_madt_nmi_source __initdata *nmisrc; static int __init modify_identity_mmio(struct domain *d, unsigned long pfn, unsigned long nr_pages, const bool map) { - int rc; - - for ( ; ; ) - { - rc = (map ? map_mmio_regions : unmap_mmio_regions) - (d, _gfn(pfn), nr_pages, _mfn(pfn)); - if ( rc == 0 ) - break; - if ( rc < 0 ) - { - printk(XENLOG_WARNING - "Failed to identity %smap [%#lx,%#lx) for d%d: %d\n", - map ? "" : "un", pfn, pfn + nr_pages, d->domain_id, rc); - break; - } - nr_pages -= rc; - pfn += rc; - process_pending_softirqs(); - } - - return rc; + return modify_mmio(d, _gfn(pfn), _mfn(pfn), nr_pages, map); } /* Populate a HVM memory range using the biggest possible order. */ diff --git a/xen/common/memory.c b/xen/common/memory.c index 52879e7438..888b3f2f4f 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1438,6 +1438,42 @@ int prepare_ring_for_helper( return 0; } +int modify_mmio(struct domain *d, gfn_t gfn, mfn_t mfn, unsigned long nr_pages, + const bool map) +{ + int rc; + + /* + * Make sure this function is only used by the hardware domain, because it + * can take an arbitrary long time, and could DoS the whole system. + */ + ASSERT(is_hardware_domain(d)); + + for ( ; ; ) + { + rc = (map ? map_mmio_regions : unmap_mmio_regions) + (d, gfn, nr_pages, mfn); + if ( rc == 0 ) + break; + if ( rc < 0 ) + { + printk(XENLOG_G_WARNING + "Failed to %smap [%" PRI_gfn ", %" PRI_gfn ") -> " + "[%" PRI_mfn ", %" PRI_mfn ") for d%d: %d\n", + map ? "" : "un", gfn_x(gfn), gfn_x(gfn_add(gfn, nr_pages)), + mfn_x(mfn), mfn_x(mfn_add(mfn, nr_pages)), d->domain_id, + rc); + break; + } + nr_pages -= rc; + mfn = mfn_add(mfn, rc); + gfn = gfn_add(gfn, rc); + process_pending_softirqs(); + } + + return rc; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/p2m-common.h b/xen/include/xen/p2m-common.h index 8cd5a6b503..4f398cb847 100644 --- a/xen/include/xen/p2m-common.h +++ b/xen/include/xen/p2m-common.h @@ -13,4 +13,7 @@ int unmap_mmio_regions(struct domain *d, unsigned long nr, mfn_t mfn); +int modify_mmio(struct domain *d, gfn_t gfn, mfn_t mfn, unsigned long nr_pages, + const bool map); + #endif /* _XEN_P2M_COMMON_H */