From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCH 02/13] xen/grant-table: Move xlated_setup_gnttab_pages to common place Date: Tue, 17 Nov 2015 16:02:08 +0000 Message-ID: <564B4F80.2020402__17841.4935166531$1447776285$gmane$org@citrix.com> References: <1447754231-7772-1-git-send-email-shannon.zhao@linaro.org> <1447754231-7772-3-git-send-email-shannon.zhao@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1447754231-7772-3-git-send-email-shannon.zhao@linaro.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: shannon.zhao@linaro.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, catalin.marinas@arm.com, will.deacon@arm.com, julien.grall@citrix.com, ard.biesheuvel@linaro.org, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org Cc: devicetree@vger.kernel.org, hangaohuai@huawei.com, linux-efi@vger.kernel.org, peter.huangpeng@huawei.com, xen-devel@lists.xen.org, zhaoshenglong@huawei.com, christoffer.dall@linaro.org List-Id: xen-devel@lists.xenproject.org On 17/11/15 09:57, shannon.zhao@linaro.org wrote: > From: Shannon Zhao > > Move xlated_setup_gnttab_pages to common place, so it can be reused by > ARM to setup grant table when booting with ACPI. [...] > --- a/drivers/xen/grant-table.c > +++ b/drivers/xen/grant-table.c > @@ -664,6 +664,55 @@ int gnttab_setup_auto_xlat_frames(phys_addr_t addr) > } > EXPORT_SYMBOL_GPL(gnttab_setup_auto_xlat_frames); > > +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, 0 /* lowmem */); > + 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); Can you move most of this function into drivers/xen/xlate_mmu.c in a function like: /** * xen_xlate_map_ballooned_pages - map a new set of ballooned pages * count: number of GFNs. * pages: returns the array of (now) ballooned pages. * gfns: returns the array of corresponding GFNs. * virt: returns the virtual address of the mapped region. * * This allocate a set of ballooned pages and maps them into the * kernel's address space. */ void *xen_xlate_map_ballooned_pages( unsigned int count, struct page **pages, xen_pfn_t **gfns); David