From patchwork Wed Nov 1 11:31:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 10036263 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 7B9B6600C5 for ; Wed, 1 Nov 2017 11:34:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 786402847E for ; Wed, 1 Nov 2017 11:34:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CDDE2851D; Wed, 1 Nov 2017 11:34:31 +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 44EA528502 for ; Wed, 1 Nov 2017 11:34:29 +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 1e9rFH-0004nY-Re; Wed, 01 Nov 2017 11:31:43 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9rFG-0004nS-Lt for xen-devel@lists.xenproject.org; Wed, 01 Nov 2017 11:31:42 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id E8/02-17628-D90B9F95; Wed, 01 Nov 2017 11:31:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXnfuhp+ RBss/8ll83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBn9X/axFMwyqDj58RJbA+NF9S5GTg4JAX+J Sx8mMYLYbAI6ElOfXmLtYuTgEBEIl5j4tbKLkYuDWeAJo8ScLafZQGqEBVwkdixfwARiswioS PzYthmsl1fAWmLe8qPMEDPlJXa1XWQFsYWAatZPncUGUSMocXLmExYQm1lAQuLgixfMExi5Zy FJzUKSWsDItIpRozi1qCy1SNfQSC+pKDM9oyQ3MTNH19DAVC83tbg4MT01JzGpWC85P3cTIzA YGIBgB2PfLOdDjJIcTEqivDsdv0cK8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuDduP5npJBgUWp6 akVaZg4wLGHSEhw8SiK8eSBp3uKCxNzizHSI1ClGS45jmy7/YeLouHkXSD6b+bqBWYglLz8vV UqctxekQQCkIaM0D24cLHYuMcpKCfMyAh0oxFOQWpSbWYIq/4pRnINRSZi3A2QKT2ZeCdzWV0 AHMQEd5CXxA+SgkkSElFQD40STgyssF1XZbudPumd+vGea5AXRR7olX432aF/6a8vF/Ct9czL /4r6TTs8S9VMVVzzYyZPkZCH6+2usr4jJsek9LuyS814c3rV649tCX+d/N0VnPe2VvnvjbMKX b/cW2KpyaxoXm8ayOR170XYmLyZqQtgVMU+jjnPf/snpPJnFanbnv9iGRiWW4oxEQy3mouJEA EeU/LeYAgAA X-Env-Sender: prvs=471739bdf=Paul.Durrant@citrix.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1509535899!81191749!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.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 65510 invoked from network); 1 Nov 2017 11:31:41 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-10.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 1 Nov 2017 11:31:41 -0000 X-IronPort-AV: E=Sophos;i="5.44,327,1505779200"; d="scan'208";a="457229221" From: Paul Durrant To: , , Date: Wed, 1 Nov 2017 11:31:36 +0000 Message-ID: <20171101113136.1844-1-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Cc: Juergen Gross , Paul Durrant , Thomas Gleixner , "H. Peter Anvin" , Boris Ostrovsky , Ingo Molnar Subject: [Xen-devel] [PATCH v2] xen: support priv-mapping in an HVM tools domain 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 If the domain has XENFEAT_auto_translated_physmap then use of the PV- specific HYPERVISOR_mmu_update hypercall is clearly incorrect. This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. This patch also moves xen_remap_domain_gfn_range() into the PV-only MMU code and #ifdefs the (only) calling code in privcmd accordingly. Signed-off-by: Paul Durrant Reviewed-by: Boris Ostrovsky --- Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" --- arch/x86/xen/mmu.c | 36 +++++++++++++++++------------------- arch/x86/xen/mmu_pv.c | 11 +++++++++++ drivers/xen/privcmd.c | 17 +++++++++++++---- include/xen/xen-ops.h | 7 +++++++ 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c index 3e15345abfe7..01837c36e293 100644 --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c @@ -91,12 +91,12 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token, return 0; } -static int do_remap_gfn(struct vm_area_struct *vma, - unsigned long addr, - xen_pfn_t *gfn, int nr, - int *err_ptr, pgprot_t prot, - unsigned domid, - struct page **pages) +int xen_remap_gfn(struct vm_area_struct *vma, + unsigned long addr, + xen_pfn_t *gfn, int nr, + int *err_ptr, pgprot_t prot, + unsigned int domid, + struct page **pages) { int err = 0; struct remap_data rmd; @@ -166,36 +166,34 @@ static int do_remap_gfn(struct vm_area_struct *vma, return err < 0 ? err : mapped; } -int xen_remap_domain_gfn_range(struct vm_area_struct *vma, - unsigned long addr, - xen_pfn_t gfn, int nr, - pgprot_t prot, unsigned domid, - struct page **pages) -{ - return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages); -} -EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range); - int xen_remap_domain_gfn_array(struct vm_area_struct *vma, unsigned long addr, xen_pfn_t *gfn, int nr, int *err_ptr, pgprot_t prot, unsigned domid, struct page **pages) { + if (xen_feature(XENFEAT_auto_translated_physmap)) + return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr, + prot, domid, pages); + /* We BUG_ON because it's a programmer error to pass a NULL err_ptr, * and the consequences later is quite hard to detect what the actual * cause of "wrong memory was mapped in". */ BUG_ON(err_ptr == NULL); - return do_remap_gfn(vma, addr, gfn, nr, err_ptr, prot, domid, pages); + return xen_remap_gfn(vma, addr, gfn, nr, err_ptr, prot, domid, + pages); } EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array); /* Returns: 0 success */ int xen_unmap_domain_gfn_range(struct vm_area_struct *vma, - int numpgs, struct page **pages) + int nr, struct page **pages) { - if (!pages || !xen_feature(XENFEAT_auto_translated_physmap)) + if (xen_feature(XENFEAT_auto_translated_physmap)) + return xen_xlate_unmap_gfn_range(vma, nr, pages); + + if (!pages) return 0; return -EINVAL; diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c index 71495f1a86d7..4974d8a6c2b4 100644 --- a/arch/x86/xen/mmu_pv.c +++ b/arch/x86/xen/mmu_pv.c @@ -2670,3 +2670,14 @@ phys_addr_t paddr_vmcoreinfo_note(void) return __pa(vmcoreinfo_note); } #endif /* CONFIG_KEXEC_CORE */ + +int xen_remap_domain_gfn_range(struct vm_area_struct *vma, + unsigned long addr, + xen_pfn_t gfn, int nr, + pgprot_t prot, unsigned int domid, + struct page **pages) +{ + return xen_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, + pages); +} +EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range); diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index feca75b07fdd..b58a1719b606 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -215,6 +215,8 @@ static int traverse_pages_block(unsigned nelem, size_t size, return ret; } +#ifdef CONFIG_XEN_PV + struct mmap_gfn_state { unsigned long va; struct vm_area_struct *vma; @@ -261,10 +263,6 @@ static long privcmd_ioctl_mmap(struct file *file, void __user *udata) LIST_HEAD(pagelist); struct mmap_gfn_state state; - /* We only support privcmd_ioctl_mmap_batch for auto translated. */ - if (xen_feature(XENFEAT_auto_translated_physmap)) - return -ENOSYS; - if (copy_from_user(&mmapcmd, udata, sizeof(mmapcmd))) return -EFAULT; @@ -312,6 +310,17 @@ static long privcmd_ioctl_mmap(struct file *file, void __user *udata) return rc; } +#else + +static long privcmd_ioctl_mmap(struct file *file, void __user *udata) +{ + /* We only support privcmd_ioctl_mmap for PV. */ + return -ENOSYS; +} + + +#endif /* CONFIG_XEN_PV */ + struct mmap_batch_state { domid_t domain; unsigned long va; diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 218e6aae5433..663a9a06b762 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -60,6 +60,10 @@ static inline void xen_destroy_contiguous_region(phys_addr_t pstart, struct vm_area_struct; +int xen_remap_gfn(struct vm_area_struct *vma, unsigned long addr, + xen_pfn_t *gfn, int nr, int *err_ptr, pgprot_t prot, + unsigned int domid, struct page **pages); + /* * xen_remap_domain_gfn_array() - map an array of foreign frames * @vma: VMA to map the pages into @@ -84,6 +88,7 @@ int xen_remap_domain_gfn_array(struct vm_area_struct *vma, unsigned domid, struct page **pages); +#ifdef CONFIG_XEN_PV /* xen_remap_domain_gfn_range() - map a range of foreign frames * @vma: VMA to map the pages into * @addr: Address at which to map the pages @@ -101,6 +106,8 @@ int xen_remap_domain_gfn_range(struct vm_area_struct *vma, xen_pfn_t gfn, int nr, pgprot_t prot, unsigned domid, struct page **pages); +#endif + int xen_unmap_domain_gfn_range(struct vm_area_struct *vma, int numpgs, struct page **pages); int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,