From patchwork Tue Jul 8 15:53:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 33238 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0D9B72070A for ; Tue, 8 Jul 2014 15:55:11 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id j17sf35963299oag.8 for ; Tue, 08 Jul 2014 08:55:10 -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=xtAhGlVPLn/s9gKnXhJC47VGuLey85Xo7HiaY7EGPe4=; b=kIGHhQ0TkpT+zH1C1WDsUoQTTNtN4lS8SLx9b6q8hPwfUnuvRLoIKksd8QXYi/WYgu GBV4nyk1Xd77H4/6odu7FArE6wuXinT9Y/NkzicowrH4UJYZK+sLZt9fqugoCMfU5eBw 2ijlZAXNG1LCHkDewWQxA8RpRkYvZnwNsAqnVtz7c2Icyw9lV2Swc2QkngVMeHvHoQ+U i0Kz74mzu2Yqe0AEXFTCeQ0UglhsNcIK9jaJgCJYAMNF/0FoKeG550IlHCmY8yEXRpis ZLAOKd6mvfOf4VHYUtlHBRPfn3z4v2VZgxuBsDXrU4dw+9JPC6eL/Sybtchziml413H2 Plxw== X-Gm-Message-State: ALoCoQnSf7XcjxRe0C6gisxC1nUSQLyHP9nCMgIDbU3yffhUpH9pA2wALKmSzUwD0UsZv9hQ8gZ+ X-Received: by 10.182.28.5 with SMTP id x5mr7650686obg.44.1404834910666; Tue, 08 Jul 2014 08:55:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.34 with SMTP id i31ls2185618qgf.51.gmail; Tue, 08 Jul 2014 08:55:10 -0700 (PDT) X-Received: by 10.52.166.71 with SMTP id ze7mr928140vdb.69.1404834910584; Tue, 08 Jul 2014 08:55:10 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id rw10si20330022vcb.44.2014.07.08.08.55.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Jul 2014 08:55:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id i13so5817296veh.36 for ; Tue, 08 Jul 2014 08:55:10 -0700 (PDT) X-Received: by 10.58.30.35 with SMTP id p3mr34239649veh.25.1404834910498; Tue, 08 Jul 2014 08:55:10 -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 tc5csp781977vcb; Tue, 8 Jul 2014 08:55:10 -0700 (PDT) X-Received: by 10.140.29.66 with SMTP id a60mr57242591qga.76.1404834910093; Tue, 08 Jul 2014 08:55:10 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id b7si55904169qai.88.2014.07.08.08.55.09 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Jul 2014 08:55: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 1X4Xib-0002DA-Pq; Tue, 08 Jul 2014 15:54:09 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X4Xia-0002Cl-00 for xen-devel@lists.xensource.com; Tue, 08 Jul 2014 15:54:08 +0000 Received: from [193.109.254.147:47523] by server-11.bemta-14.messagelabs.com id 1F/F7-12767-F141CB35; Tue, 08 Jul 2014 15:54:07 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1404834844!16175343!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5826 invoked from network); 8 Jul 2014 15:54:06 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-7.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 8 Jul 2014 15:54:06 -0000 X-IronPort-AV: E=Sophos;i="5.01,625,1400025600"; d="scan'208";a="150609958" Received: from accessns.citrite.net (HELO FTLPEX01CL01.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 08 Jul 2014 15:54:05 +0000 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; Tue, 8 Jul 2014 11:54:03 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1X4XiQ-0000M3-JC; Tue, 08 Jul 2014 16:53:58 +0100 From: Stefano Stabellini To: Date: Tue, 8 Jul 2014 16:53:13 +0100 Message-ID: <1404834794-16055-1-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, Stefano Stabellini Subject: [Xen-devel] [RFC PATCH 1/2] xen: introduce arch_iommu_grant_(un)map_page 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.128.177 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: From: Julien Grall From: Julien Grall Introduce two arch specific iommu grant mapping and unmapping functions, they are called from __gnttab_map_grant_ref and __gnttab_unmap_common. The x86 implementation simply calls iommu_(un)map_page. The ARM implementation is based on arm_smmu_(un)map_page. Signed-off-by: Julien Grall Signed-off-by: Stefano Stabellini --- xen/common/grant_table.c | 10 +++---- xen/drivers/passthrough/arm/iommu.c | 49 +++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/arm/smmu.c | 42 ------------------------------ xen/drivers/passthrough/x86/iommu.c | 11 ++++++++ xen/include/xen/iommu.h | 4 +++ 5 files changed, 69 insertions(+), 47 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 464007e..6ea1c2f 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -738,13 +738,13 @@ __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); + err = arch_iommu_grant_map_page(ld, frame, + IOMMUF_readable|IOMMUF_writable); } else if ( act_pin && !old_pin ) { if ( (wrc + rdc) == 0 ) - err = iommu_map_page(ld, frame, frame, IOMMUF_readable); + err = arch_iommu_grant_map_page(ld, frame, IOMMUF_readable); } if ( err ) { @@ -941,9 +941,9 @@ __gnttab_unmap_common( int err = 0; mapcount(lgt, rd, op->frame, &wrc, &rdc); if ( (wrc + rdc) == 0 ) - err = iommu_unmap_page(ld, op->frame); + err = arch_iommu_grant_unmap_page(ld, op->frame); else if ( wrc == 0 ) - err = iommu_map_page(ld, op->frame, op->frame, IOMMUF_readable); + err = arch_iommu_grant_map_page(ld, op->frame, IOMMUF_readable); if ( err ) { rc = GNTST_general_error; diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index 3007b99..6460b7e 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include static const struct iommu_ops *iommu_ops; @@ -68,3 +70,50 @@ void arch_iommu_domain_destroy(struct domain *d) { iommu_dt_domain_destroy(d); } + +int arch_iommu_grant_map_page(struct domain *d, unsigned long frame, + unsigned flags) +{ + p2m_type_t t; + + /* 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. + */ + BUG_ON(!is_domain_direct_mapped(d)); + + /* We only support readable and writable flags */ + if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) ) + return -EINVAL; + + t = (flags & IOMMUF_writable) ? p2m_iommu_map_rw : p2m_iommu_map_ro; + + /* The function guest_physmap_add_entry replaces the current mapping + * if there is already one... + */ + return guest_physmap_add_entry(d, frame, frame, 0, t); +} + +int arch_iommu_grant_unmap_page(struct domain *d, unsigned long frame) +{ + /* This function should only be used by gnttab code when the domain + * is direct mapped + */ + if ( !is_domain_direct_mapped(d) ) + return -EINVAL; + + guest_physmap_remove_page(d, frame, frame, 0); + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index f4eb2a2..21b4572 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -1536,46 +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) -{ - p2m_type_t t; - - /* 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; - - t = (flags & IOMMUF_writable) ? p2m_iommu_map_rw : p2m_iommu_map_ro; - - /* The function guest_physmap_add_entry replaces the current mapping - * if there is already one... - */ - return guest_physmap_add_entry(d, gfn, mfn, 0, t); -} - -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; - - guest_physmap_remove_page(d, gfn, gfn, 0); - - return 0; -} - static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, .hwdom_init = arm_smmu_iommu_hwdom_init, @@ -1584,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/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index ce0ca5a..a88626a 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -135,6 +135,17 @@ void arch_iommu_domain_destroy(struct domain *d) } } +int arch_iommu_grant_map_page(struct domain *d, unsigned long frame, + unsigned flags) +{ + return iommu_map_page(d, frame, frame, flags); +} + +int arch_iommu_grant_unmap_page(struct domain *d, unsigned long frame) +{ + return iommu_unmap_page(d, frame); +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 8eb764a..0dd6987 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -76,6 +76,10 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, unsigned int flags); int iommu_unmap_page(struct domain *d, unsigned long gfn); +int arch_iommu_grant_map_page(struct domain *d, unsigned long frame, + unsigned flags); +int arch_iommu_grant_unmap_page(struct domain *d, unsigned long frame); + enum iommu_feature { IOMMU_FEAT_COHERENT_WALK,