From patchwork Thu Apr 20 15:17:37 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: 9690797 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 6123C600C8 for ; Thu, 20 Apr 2017 15:21:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4919B24DA2 for ; Thu, 20 Apr 2017 15:21:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DD0C28489; Thu, 20 Apr 2017 15:21:04 +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 BA33F24DA2 for ; Thu, 20 Apr 2017 15:21:03 +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 1d1DrM-00062y-3H; Thu, 20 Apr 2017 15:19:04 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DrL-00062D-1i for xen-devel@lists.xenproject.org; Thu, 20 Apr 2017 15:19:03 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 43/00-02005-661D8F85; Thu, 20 Apr 2017 15:19:02 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNIsWRWlGSWpSXmKPExsXitHSDvW7qxR8 RBvualSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozf004xFfRIVSzoX8nWwHhXqIuRk0NCwF+i 98Y5ZhCbTUBH4uLcnWxdjBwcIgIqErf3GnQxcnEwC2xglJj++DYrSFxYIEJiywYHkHIWAVWJT 827GUFsXgFLiSMnPzJDjNSTeDvxBSNIOaeAlcTiT2EgYSGgkoM9x6HKBSVOznzCAmIzC2hKtG 7/zQ5hy0s0b53NDFGvKNE/7wHbBEa+WUhaZiFpmYWkZQEj8ypGjeLUorLUIl1jA72kosz0jJL cxMwcXUMDY73c1OLixPTUnMSkYr3k/NxNjMBAq2dgYNzB2HnC7xCjJAeTkiiv2twfEUJ8Sfkp lRmJxRnxRaU5qcWHGGU4OJQkeJMuAOUEi1LTUyvSMnOAIQ+TluDgURLhbTsPlOYtLkjMLc5Mh 0idYlSUEuc9B9InAJLIKM2Da4PF2SVGWSlhXkYGBgYhnoLUotzMElT5V4ziHIxKwrwzQabwZO aVwE1/BbSYCWjxWT+wxSWJCCmpBsbSFYIvPk4QLM2w2fgrh7/l9yt+w73JN5K/Rs2Y8aKs9db uTW2nb7SFKrk+bvxQevJ5zOpgZf6NT2L/NIVpeFWneeoFWsbfF2Sv5nnMw7li++9t0uc9dG5H n7pecfSh1bxZz9f5Pjr2KVizQif2Tdkd61+fb3KYGc1Zo2gi8CLK5+zqzd/eHV+sxFKckWiox VxUnAgAJXqK+K4CAAA= X-Env-Sender: prvs=2769e1f82=roger.pau@citrix.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1492701539!93369839!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37182 invoked from network); 20 Apr 2017 15:19:01 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 20 Apr 2017 15:19:01 -0000 X-IronPort-AV: E=Sophos;i="5.37,225,1488844800"; d="scan'208";a="428833791" From: Roger Pau Monne To: Date: Thu, 20 Apr 2017 16:17:37 +0100 Message-ID: <20170420151743.90889-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) In-Reply-To: <20170420151743.90889-1-roger.pau@citrix.com> References: <20170420151743.90889-1-roger.pau@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , boris.ostrovsky@oracle.com, Roger Pau Monne , Jan Beulich Subject: [Xen-devel] [PATCH v2 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. Signed-off-by: Roger Pau Monné --- Cc: Jan Beulich Cc: Andrew Cooper --- xen/arch/x86/hvm/dom0_build.c | 22 +--------------------- xen/common/memory.c | 34 ++++++++++++++++++++++++++++++++++ xen/include/xen/p2m-common.h | 4 ++++ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index ca88c5835e..65f606d33a 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, pfn, 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..0d970482cb 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1438,6 +1438,40 @@ int prepare_ring_for_helper( return 0; } +int modify_mmio(struct domain *d, unsigned long gfn, unsigned long pfn, + 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(gfn), nr_pages, _mfn(pfn)); + if ( rc == 0 ) + break; + if ( rc < 0 ) + { + printk(XENLOG_WARNING + "Failed to %smap [%#lx, %#lx) -> [%#lx,%#lx) for d%d: %d\n", + map ? "" : "un", gfn, gfn + nr_pages, pfn, pfn + nr_pages, + d->domain_id, rc); + break; + } + nr_pages -= rc; + pfn += rc; + 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..1308da44e7 100644 --- a/xen/include/xen/p2m-common.h +++ b/xen/include/xen/p2m-common.h @@ -13,4 +13,8 @@ int unmap_mmio_regions(struct domain *d, unsigned long nr, mfn_t mfn); + +int modify_mmio(struct domain *d, unsigned long gfn, unsigned long pfn, + unsigned long nr_pages, const bool map); + #endif /* _XEN_P2M_COMMON_H */