From patchwork Tue May 13 15:50:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 30080 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A27C820446 for ; Tue, 13 May 2014 15:52:01 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf2426194pab.9 for ; Tue, 13 May 2014 08:52:00 -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:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=VpCin4guyNH5X49BdjmU2VYz3ByFNULI6pfG/Lgn5rg=; b=LJhHbmKmV9WvbDWTDHpQd56mQ2DolFWIwWmvCHrUkOrIiu10FAxDQLUqdugdJ1kYIg EabVc6DbKXAY5UuVpAYj24ZOCm0vd7f3ZpFG4VxTpG7vU1/eAFjkYhJTeeqIsNHTN5Qi O5oHeXZYgLHcwXusNCRFiMwOEZ8YT2AyjN27y9V0S93gzTW3RhYJaNcwuJ/imu/JrPMU BrJpFuzfD+2KDcPavhvl5cxpe3E1f6GcDlKaLt6tDY6bII7zeevP72HKh992pAdFDyF4 WFBTJyf/UlFz+JQXIyykruGqq0vHlxluHR46rWkXrJ5L2XSJ6Yxpr9Ne0kDJUhtRHkps Zk+A== X-Gm-Message-State: ALoCoQl9WRNCkyEH0TyHsLV+E4pXwECIUr/XXiO66Fc4jnDtUvh8G7IkVhWRxRmTk0BZs7d3bza7 X-Received: by 10.68.195.9 with SMTP id ia9mr2691718pbc.7.1399996320903; Tue, 13 May 2014 08:52:00 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.37 with SMTP id u34ls1996541qgu.4.gmail; Tue, 13 May 2014 08:52:00 -0700 (PDT) X-Received: by 10.58.28.204 with SMTP id d12mr81295veh.81.1399996320756; Tue, 13 May 2014 08:52:00 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id o6si2719366vcz.76.2014.05.13.08.52.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 08:52:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.175 as permitted sender) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id jw12so689684veb.20 for ; Tue, 13 May 2014 08:52:00 -0700 (PDT) X-Received: by 10.221.7.71 with SMTP id on7mr4640967vcb.18.1399996320647; Tue, 13 May 2014 08:52:00 -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.220.221.72 with SMTP id ib8csp162069vcb; Tue, 13 May 2014 08:52:00 -0700 (PDT) X-Received: by 10.52.182.227 with SMTP id eh3mr1933409vdc.40.1399996319345; Tue, 13 May 2014 08:51:59 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id cx1si2707365vdb.182.2014.05.13.08.51.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 May 2014 08:51:59 -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 1WkEyr-0000DG-2y; Tue, 13 May 2014 15:51:01 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WkEyo-00009U-I5 for xen-devel@lists.xenproject.org; Tue, 13 May 2014 15:50:58 +0000 Received: from [193.109.254.147:49470] by server-5.bemta-14.messagelabs.com id D6/DB-26413-16F32735; Tue, 13 May 2014 15:50:57 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-4.tower-27.messagelabs.com!1399996256!4556678!1 X-Originating-IP: [74.125.83.49] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 16104 invoked from network); 13 May 2014 15:50:57 -0000 Received: from mail-ee0-f49.google.com (HELO mail-ee0-f49.google.com) (74.125.83.49) by server-4.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 13 May 2014 15:50:57 -0000 Received: by mail-ee0-f49.google.com with SMTP id e53so548580eek.22 for ; Tue, 13 May 2014 08:50:56 -0700 (PDT) X-Received: by 10.14.110.2 with SMTP id t2mr4199705eeg.108.1399996256844; Tue, 13 May 2014 08:50:56 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id m44sm41054917eeh.14.2014.05.13.08.50.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 May 2014 08:50:56 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 13 May 2014 16:50:29 +0100 Message-Id: <1399996230-18201-14-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399996230-18201-1-git-send-email-julien.grall@linaro.org> References: <1399996230-18201-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v5 13/14] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m 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: , MIME-Version: 1.0 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: julien.grall@linaro.org 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.175 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: Grant mapping can be used for DMA request. The dev_bus_addr returned by the hypercall is the MFN (not the IPA). Currently Linux is using this address (via swiotlb) to program the DMA. When the device is protected by IOMMU the request will fail. We have to add 1:1 mapping in the domain p2m to allow DMA request working. This is valid because DOM0 has its memory mapped 1:1 and therefore we know that RAM and devices cannot clash. Signed-off-by: Julien Grall Acked-by: Ian Campbell --- Changes in v5: - Update commit message Changes in v4: - Patch added --- xen/arch/arm/mm.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index eac228c..4ce3962 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1199,6 +1199,7 @@ int create_grant_host_mapping(unsigned long addr, unsigned long frame, { int rc; p2m_type_t t = p2m_grant_map_rw; + struct domain *d = current->domain; if ( cache_flags || (flags & ~GNTMAP_readonly) != GNTMAP_host_map ) return GNTST_general_error; @@ -1206,13 +1207,32 @@ int create_grant_host_mapping(unsigned long addr, unsigned long frame, if ( flags & GNTMAP_readonly ) t = p2m_grant_map_ro; - rc = guest_physmap_add_entry(current->domain, addr >> PAGE_SHIFT, - frame, 0, t); + rc = guest_physmap_add_entry(d, addr >> PAGE_SHIFT, frame, 0, t); if ( rc ) - return GNTST_general_error; - else - return GNTST_okay; + goto gerror; + + /* Grant mapping can be used for DMA request. 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 working. + * This is only valid when the domain is directed mapped + */ + if ( is_domain_direct_mapped(d) && need_iommu(d) ) + { + rc = guest_physmap_add_entry(d, frame, frame, 0, t); + if ( rc ) + goto unmap; + } + + return GNTST_okay; + +unmap: + guest_physmap_remove_page(d, addr >> PAGE_SHIFT, frame, 0); + +gerror: + return GNTST_general_error; + } int replace_grant_host_mapping(unsigned long addr, unsigned long mfn, @@ -1226,6 +1246,9 @@ int replace_grant_host_mapping(unsigned long addr, unsigned long mfn, guest_physmap_remove_page(d, gfn, mfn, 0); + if ( is_domain_direct_mapped(d) && need_iommu(d) ) + guest_physmap_remove_page(d, mfn, mfn, 0); + return GNTST_okay; }