From patchwork Thu Apr 7 12:03:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 8771951 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 59E809F39A for ; Thu, 7 Apr 2016 12:10:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2BEDC2024F for ; Thu, 7 Apr 2016 12:10:19 +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 F2BC22020F for ; Thu, 7 Apr 2016 12:10:17 +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 1ao8jc-0003Nf-I9; Thu, 07 Apr 2016 12:08:28 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ao8jb-0003NG-Gv for xen-devel@lists.xen.org; Thu, 07 Apr 2016 12:08:27 +0000 Received: from [193.109.254.147] by server-9.bemta-14.messagelabs.com id DE/EB-02984-ABD46075; Thu, 07 Apr 2016 12:08:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVSPpHPSXeXL1u 4weq3whZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bzvxeZCj5rVsy4Z9zA+FG5i5GLQ0jgFKNE 2+SZbBDObkaJO2u+s3YxcnKwCehKfNw4hb2LkYNDRMBF4thnL5AaZoFtTBJHW7exgdQIC0RJb Nl8E8xmEVCRmD91BjOIzSvgIXF22mt2EFtCQENiZe8EFhCbU8BToq19Ith8IaCaHS3zmCDqBS VOznwCVsMsICFx8MULZoheRYm29SfZIGxJiYMrbrCAHCEBcvWrtXuYIBKmEvd37mGawCg4C8m sWUhmLWBkWsWoUZxaVJZapGtopJdUlJmeUZKbmJmja2hoopebWlycmJ6ak5hUrJecn7uJERig DECwg/HsNOdDjJIcTEqivNNd2cKF+JLyUyozEosz4otKc1KLDzHKcHAoSfCe8wbKCRalpqdWp GXmAGMFJi3BwaMkwsvhA5TmLS5IzC3OTIdInWJUlBLnDQNJCIAkMkrz4Npg8XmJUVZKmJcR6B AhnoLUotzMElT5V4ziHIxKwryBIFN4MvNK4Ka/AlrMBLT4Aj/Y4pJEhJRUA2P7S9+YAxNjdbZ oiVUXr/zGWzsndFVvyESZ5YFf1r8XfPG2wlrhg9rOE/G7bRy/bDxQJf7IfZ9ps0C62mwrX/HV m5vmhLnVZ9x89+HIrl05Ib95N7Xe+qCbnm1bkznHzM5x3vuA9JjPFo943OvSwzMfRVxNnRR43 kyY89DeO4mbN/JffhAxu0CJpTgj0VCLuag4EQAIfDxeygIAAA== X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1460030891!36184541!1 X-Originating-IP: [119.145.14.66] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTE5LjE0NS4xNC42NiA9PiA4NTI3\n X-StarScan-Received: X-StarScan-Version: 8.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26643 invoked from network); 7 Apr 2016 12:08:25 -0000 Received: from unknown (HELO szxga03-in.huawei.com) (119.145.14.66) by server-7.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 7 Apr 2016 12:08:25 -0000 Received: from 172.24.1.60 (EHLO SZXEML424-HUB.china.huawei.com) ([172.24.1.60]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BZL25427; Thu, 07 Apr 2016 20:04:15 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by SZXEML424-HUB.china.huawei.com (10.82.67.153) with Microsoft SMTP Server id 14.3.235.1; Thu, 7 Apr 2016 20:04:05 +0800 From: Shannon Zhao To: , Date: Thu, 7 Apr 2016 20:03:19 +0800 Message-ID: <1460030614-16112-3-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1460030614-16112-1-git-send-email-zhaoshenglong@huawei.com> References: <1460030614-16112-1-git-send-email-zhaoshenglong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090205.57064CC1.005D, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: f737ed6475cd04d15d7ba83f686e95d5 Cc: devicetree@vger.kernel.org, linux-efi@vger.kernel.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, xen-devel@lists.xen.org, julien.grall@arm.com, david.vrabel@citrix.com, peter.huangpeng@huawei.com, shannon.zhao@linaro.org Subject: [Xen-devel] [PATCH v11 02/17] xen/grant-table: Move xlated_setup_gnttab_pages to common place 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-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 From: Shannon Zhao Move xlated_setup_gnttab_pages to common place, so it can be reused by ARM to setup grant table. Rename it to xen_xlate_map_ballooned_pages. Signed-off-by: Shannon Zhao Reviewed-by: Stefano Stabellini Reviewed-by: Julien Grall --- arch/x86/xen/grant-table.c | 57 +++++-------------------------------------- drivers/xen/xlate_mmu.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++ include/xen/xen-ops.h | 2 ++ 3 files changed, 69 insertions(+), 51 deletions(-) diff --git a/arch/x86/xen/grant-table.c b/arch/x86/xen/grant-table.c index e079500..de4144c 100644 --- a/arch/x86/xen/grant-table.c +++ b/arch/x86/xen/grant-table.c @@ -111,63 +111,18 @@ int arch_gnttab_init(unsigned long nr_shared) } #ifdef CONFIG_XEN_PVH -#include #include -#include -static int __init xlated_setup_gnttab_pages(void) -{ - struct page **pages; - xen_pfn_t *pfns; - void *vaddr; - int rc; - unsigned int i; - unsigned long nr_grant_frames = gnttab_max_grant_frames(); - - BUG_ON(nr_grant_frames == 0); - pages = kcalloc(nr_grant_frames, sizeof(pages[0]), GFP_KERNEL); - if (!pages) - return -ENOMEM; - - pfns = kcalloc(nr_grant_frames, sizeof(pfns[0]), GFP_KERNEL); - if (!pfns) { - kfree(pages); - return -ENOMEM; - } - rc = alloc_xenballooned_pages(nr_grant_frames, pages); - if (rc) { - pr_warn("%s Couldn't balloon alloc %ld pfns rc:%d\n", __func__, - nr_grant_frames, rc); - kfree(pages); - kfree(pfns); - return rc; - } - for (i = 0; i < nr_grant_frames; i++) - pfns[i] = page_to_pfn(pages[i]); - - vaddr = vmap(pages, nr_grant_frames, 0, PAGE_KERNEL); - if (!vaddr) { - pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__, - nr_grant_frames, rc); - free_xenballooned_pages(nr_grant_frames, pages); - kfree(pages); - kfree(pfns); - return -ENOMEM; - } - kfree(pages); - - xen_auto_xlat_grant_frames.pfn = pfns; - xen_auto_xlat_grant_frames.count = nr_grant_frames; - xen_auto_xlat_grant_frames.vaddr = vaddr; - - return 0; -} - +#include static int __init xen_pvh_gnttab_setup(void) { if (!xen_pvh_domain()) return -ENODEV; - return xlated_setup_gnttab_pages(); + xen_auto_xlat_grant_frames.count = gnttab_max_grant_frames(); + + return xen_xlate_map_ballooned_pages(&xen_auto_xlat_grant_frames.pfn, + &xen_auto_xlat_grant_frames.vaddr, + xen_auto_xlat_grant_frames.count); } /* Call it _before_ __gnttab_init as we need to initialize the * xen_auto_xlat_grant_frames first. */ diff --git a/drivers/xen/xlate_mmu.c b/drivers/xen/xlate_mmu.c index 5063c5e..9692656 100644 --- a/drivers/xen/xlate_mmu.c +++ b/drivers/xen/xlate_mmu.c @@ -29,6 +29,8 @@ */ #include #include +#include +#include #include #include @@ -37,6 +39,7 @@ #include #include #include +#include typedef void (*xen_gfn_fn_t)(unsigned long gfn, void *data); @@ -185,3 +188,61 @@ int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma, return 0; } EXPORT_SYMBOL_GPL(xen_xlate_unmap_gfn_range); + +/** + * xen_xlate_map_ballooned_pages - map a new set of ballooned pages + * @gfns: returns the array of corresponding GFNs + * @virt: returns the virtual address of the mapped region + * @nr_grant_frames: number of GFNs + * @return 0 on success, error otherwise + * + * This allocates a set of ballooned pages and maps them into the + * kernel's address space. + */ +int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt, + unsigned long nr_grant_frames) +{ + struct page **pages; + xen_pfn_t *pfns; + void *vaddr; + int rc; + unsigned int i; + + BUG_ON(nr_grant_frames == 0); + pages = kcalloc(nr_grant_frames, sizeof(pages[0]), GFP_KERNEL); + if (!pages) + return -ENOMEM; + + pfns = kcalloc(nr_grant_frames, sizeof(pfns[0]), GFP_KERNEL); + if (!pfns) { + kfree(pages); + return -ENOMEM; + } + rc = alloc_xenballooned_pages(nr_grant_frames, pages); + if (rc) { + pr_warn("%s Couldn't balloon alloc %ld pfns rc:%d\n", __func__, + nr_grant_frames, rc); + kfree(pages); + kfree(pfns); + return rc; + } + for (i = 0; i < nr_grant_frames; i++) + pfns[i] = page_to_pfn(pages[i]); + + vaddr = vmap(pages, nr_grant_frames, 0, PAGE_KERNEL); + if (!vaddr) { + pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__, + nr_grant_frames, rc); + free_xenballooned_pages(nr_grant_frames, pages); + kfree(pages); + kfree(pfns); + return -ENOMEM; + } + kfree(pages); + + *gfns = pfns; + *virt = vaddr; + + return 0; +} +EXPORT_SYMBOL_GPL(xen_xlate_map_ballooned_pages); diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 86abe07..072be1c 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -85,6 +85,8 @@ int xen_xlate_remap_gfn_array(struct vm_area_struct *vma, struct page **pages); int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma, int nr, struct page **pages); +int xen_xlate_map_ballooned_pages(xen_pfn_t **pfns, void **vaddr, + unsigned long nr_grant_frames); bool xen_running_on_version_or_later(unsigned int major, unsigned int minor);