From patchwork Fri Aug 1 14:45:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 34705 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f71.google.com (mail-qg0-f71.google.com [209.85.192.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0A6B32062F for ; Fri, 1 Aug 2014 14:49:12 +0000 (UTC) Received: by mail-qg0-f71.google.com with SMTP id f51sf8353964qge.10 for ; Fri, 01 Aug 2014 07:49:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=1NpR4MWvgKwUv2l/sTDwQOlLv1S6f5Qwgiqgr58KXS4=; b=cNzBGfD2Uylv6EtKFmBIMtFxKvUMED9L0MvWVNf6Mw5E8ms2zrKwDd65JDnv0jJA5R jRNyaLuFqpksZ5LXai1LfumFSNpUO6uaeFkApyqg1JALmFprsQpKHsLLf+SWn0tIZ94a fCwGlxfQ4krREPiiT5h5/5f81CDug/nEB02e962TC2wKpWknTdQSdEt/LhoOT6rsPLN4 2Q2mhB3P9q2ux9zIWSh8rkEEmScrnDXSmmSyD5d5rruZ9hjtSwT5v+Hi20wNx2jlJInu 3V5TsBvM8oJDcZGC5OM8DCbhOCKe3p4H2gN6PasAEHUQOxfe4Zu97vqam+mPr48uBIYi qrnA== X-Gm-Message-State: ALoCoQkc5fhfwIwDd62v47lRfuw/PrBGeBQ6cBwHKSH24S4VKa5+ywTD08ytyVnjSRxUp05B/e1D X-Received: by 10.52.116.241 with SMTP id jz17mr428913vdb.9.1406904551827; Fri, 01 Aug 2014 07:49:11 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.16.179 with SMTP id 48ls1306057qgb.10.gmail; Fri, 01 Aug 2014 07:49:11 -0700 (PDT) X-Received: by 10.52.164.199 with SMTP id ys7mr5892280vdb.42.1406904551651; Fri, 01 Aug 2014 07:49:11 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id 4si624092veo.10.2014.08.01.07.49.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Aug 2014 07:49:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so6888225vcb.9 for ; Fri, 01 Aug 2014 07:49:11 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr5667906vdb.27.1406904551528; Fri, 01 Aug 2014 07:49:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp116688vcb; Fri, 1 Aug 2014 07:49:11 -0700 (PDT) X-Received: by 10.42.249.20 with SMTP id mi20mr7855680icb.90.1406904550552; Fri, 01 Aug 2014 07:49:10 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id s19si6970633igr.3.2014.08.01.07.49.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 01 Aug 2014 07:49:10 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XDE6w-0007gb-HD; Fri, 01 Aug 2014 14:47:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XDE6v-0007gM-P9 for xen-devel@lists.xensource.com; Fri, 01 Aug 2014 14:47:10 +0000 Received: from [85.158.137.68:23990] by server-1.bemta-3.messagelabs.com id 6B/7B-30185-D68ABD35; Fri, 01 Aug 2014 14:47:09 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1406904422!11286665!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13518 invoked from network); 1 Aug 2014 14:47:08 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-4.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 1 Aug 2014 14:47:08 -0000 X-IronPort-AV: E=Sophos;i="5.01,780,1400025600"; d="scan'208";a="158486353" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Fri, 1 Aug 2014 10:46:39 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XDE6L-0004ti-RO; Fri, 01 Aug 2014 15:46:33 +0100 From: Stefano Stabellini To: Date: Fri, 1 Aug 2014 15:45:25 +0100 Message-ID: <1406904325-15722-3-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 Cc: julien.grall@citrix.com, Ian.Campbell@citrix.com, JBeulich@suse.com, Stefano Stabellini Subject: [Xen-devel] [PATCH v6 3/3] xen/arm: introduce XENFEAT_grant_map_identity X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: The flag specifies that the hypervisor maps a grant page to guest physical address == machine address of the page in addition to the normal grant mapping address. Frontends are allowed to map the same page multiple times using multiple grant references. On the backend side it can be difficult to find out the physical address corresponding to a particular machine address, especially at the completion of a dma operation. To simplify address translations, we introduce a second mapping of the grant at physical address == machine address so that dom0 can issue cache maintenance operations without having to find the pfn. Call arch_grant_map_page_identity and arch_grant_unmap_page_identity from __gnttab_map_grant_ref and __gnttab_unmap_common to introduce the second mapping if the domain is directly mapped. To do so we also need to change gnttab_need_iommu_mapping to just be defined as is_domain_direct_mapped on arm. Remove arm_smmu_map_page and arm_smmu_unmap_page as they have become unused. Signed-off-by: Stefano Stabellini Acked-by: Jan Beulich Acked-by: Julien Grall --- Changes in v5: - fix coding style; - remove arm_smmu_map_page and arm_smmu_unmap_page. Changes in v4: - add XENFEAT_grant_map_identity if is_domain_direct_mapped; - remove gnttab_need_identity_mapping, check is_domain_direct_mapped instead; - define gnttab_need_iommu_mapping as is_domain_direct_mapped on arm. Changes in v3: - introduce gnttab_need_identity_mapping; - check gnttab_need_identity_mapping in __gnttab_map_grant_ref and __gnttab_unmap_common. Changes in v2: - rename XENFEAT_grant_map_11 to XENFEAT_grant_map_identity; - remove superfluous ifdef CONFIG_ARM in xen/common/kernel.c; - don't modify gnttab_need_iommu_mapping; - call arch_grant_map_page_identity and arch_grant_unmap_page_identity from grant_table functions. --- xen/common/grant_table.c | 30 +++++++++++++++++++++++++----- xen/common/kernel.c | 2 ++ xen/drivers/passthrough/arm/smmu.c | 33 --------------------------------- xen/include/asm-arm/grant_table.h | 3 +-- xen/include/public/features.h | 3 +++ 5 files changed, 31 insertions(+), 40 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 464007e..23266c3 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -738,13 +738,23 @@ __gnttab_map_grant_ref( !(old_pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) ) { if ( wrc == 0 ) - err = iommu_map_page(ld, frame, frame, - IOMMUF_readable|IOMMUF_writable); + { + if ( is_domain_direct_mapped(ld) ) + err = arch_grant_map_page_identity(ld, frame, 1); + else + err = iommu_map_page(ld, frame, frame, + IOMMUF_readable|IOMMUF_writable); + } } else if ( act_pin && !old_pin ) { if ( (wrc + rdc) == 0 ) - err = iommu_map_page(ld, frame, frame, IOMMUF_readable); + { + if ( is_domain_direct_mapped(ld) ) + err = arch_grant_map_page_identity(ld, frame, 0); + else + err = iommu_map_page(ld, frame, frame, IOMMUF_readable); + } } if ( err ) { @@ -941,9 +951,19 @@ __gnttab_unmap_common( int err = 0; mapcount(lgt, rd, op->frame, &wrc, &rdc); if ( (wrc + rdc) == 0 ) - err = iommu_unmap_page(ld, op->frame); + { + if ( is_domain_direct_mapped(ld) ) + err = arch_grant_unmap_page_identity(ld, op->frame); + else + err = iommu_unmap_page(ld, op->frame); + } else if ( wrc == 0 ) - err = iommu_map_page(ld, op->frame, op->frame, IOMMUF_readable); + { + if ( is_domain_direct_mapped(ld) ) + err = arch_grant_map_page_identity(ld, op->frame, 0); + else + err = iommu_map_page(ld, op->frame, op->frame, IOMMUF_readable); + } if ( err ) { rc = GNTST_general_error; diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 7e83353..fa40a36 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -325,6 +325,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) break; } #endif + if ( is_domain_direct_mapped(d) ) + fi.submap |= 1U << XENFEAT_grant_map_identity; break; default: return -EINVAL; diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index fb0c694..21b4572 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -1536,37 +1536,6 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d) xfree(smmu_domain); } -static int arm_smmu_map_page(struct domain *d, unsigned long gfn, - unsigned long mfn, unsigned int flags) -{ - /* Grant mappings can be used for DMA requests. The dev_bus_addr returned by - * the hypercall is the MFN (not the IPA). For device protected by - * an IOMMU, Xen needs to add a 1:1 mapping in the domain p2m to - * allow DMA request to work. - * This is only valid when the domain is directed mapped. Hence this - * function should only be used by gnttab code with gfn == mfn. - */ - BUG_ON(!is_domain_direct_mapped(d)); - BUG_ON(mfn != gfn); - - /* We only support readable and writable flags */ - if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) ) - return -EINVAL; - - return arch_grant_map_page_identity(d, mfn, flags & IOMMUF_writable); -} - -static int arm_smmu_unmap_page(struct domain *d, unsigned long gfn) -{ - /* This function should only be used by gnttab code when the domain - * is direct mapped - */ - if ( !is_domain_direct_mapped(d) ) - return -EINVAL; - - return arch_grant_unmap_page_identity(d, gfn); -} - static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, .hwdom_init = arm_smmu_iommu_hwdom_init, @@ -1575,8 +1544,6 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .iotlb_flush_all = arm_smmu_iotlb_flush_all, .assign_dt_device = arm_smmu_attach_dev, .reassign_dt_device = arm_smmu_reassign_dt_dev, - .map_page = arm_smmu_map_page, - .unmap_page = arm_smmu_unmap_page, }; static int __init smmu_init(struct dt_device_node *dev, diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h index eac8a70..47147ce 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -33,8 +33,7 @@ static inline int replace_grant_supported(void) ( ((i >= nr_grant_frames(d->grant_table)) && \ (i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i])) -#define gnttab_need_iommu_mapping(d) \ - (is_domain_direct_mapped(d) && need_iommu(d)) +#define gnttab_need_iommu_mapping(d) (is_domain_direct_mapped(d)) #endif /* __ASM_GRANT_TABLE_H__ */ /* diff --git a/xen/include/public/features.h b/xen/include/public/features.h index a149aa6..b7bf83f 100644 --- a/xen/include/public/features.h +++ b/xen/include/public/features.h @@ -94,6 +94,9 @@ /* operation as Dom0 is supported */ #define XENFEAT_dom0 11 +/* Xen also maps grant references at pfn = mfn */ +#define XENFEAT_grant_map_identity 12 + #define XENFEAT_NR_SUBMAPS 1 #endif /* __XEN_PUBLIC_FEATURES_H__ */