From patchwork Tue Apr 22 13:14:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 28810 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A600E203C3 for ; Tue, 22 Apr 2014 13:16:41 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id a41sf27884391yho.10 for ; Tue, 22 Apr 2014 06:16:41 -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=LXW480ZITt7Fh5gyEOxEUS44h640xFgCnp2loXr9sl8=; b=AZIYIJSHbHy8ztGxT90v3mwWLT7RwfJd7U35x4vES7e08AGjb7gdLZpFNxF2ci3M/E LZACvQkp7wqNncrONyQ+0WA2AjL0rXwrLJl8BKNJ8WnKfJ7Rl0p08z2XErKYMYshbz9N lxAa+73rAN+pepYoUPoTXsO79hxVRpaKQnIHBPBe/iZG4LMc6uJTEVxfdrmnfJo3gv9u KdMimu6t7E7FFtlTY6oiFxpUy85euaUs7hh/cHJsWYan+05PUgsZJTK0pyy3QaOx07ya CVblKqBuxNDdE2Hs5MkZD12/3WIDEgA84vm9L1IZUGSE8OWx1HbRfj8ZM8sDYgwSTrVm gShQ== X-Gm-Message-State: ALoCoQm72F85sOvPyg3TXCWwD/vFwb+PadgCVozTaNzJ67Io2R+tCk2EpQDC4AV9GdRGAWArOQ1t X-Received: by 10.58.59.104 with SMTP id y8mr20721519veq.18.1398172601349; Tue, 22 Apr 2014 06:16:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.112 with SMTP id n103ls86063qga.86.gmail; Tue, 22 Apr 2014 06:16:41 -0700 (PDT) X-Received: by 10.58.202.133 with SMTP id ki5mr35085559vec.19.1398172600993; Tue, 22 Apr 2014 06:16:40 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id tq2si6876233vdc.111.2014.04.22.06.16.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Apr 2014 06:16:40 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id ij19so2522249vcb.24 for ; Tue, 22 Apr 2014 06:16:40 -0700 (PDT) X-Received: by 10.52.173.165 with SMTP id bl5mr31287859vdc.13.1398172600913; Tue, 22 Apr 2014 06:16:40 -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 ib8csp23887vcb; Tue, 22 Apr 2014 06:16:40 -0700 (PDT) X-Received: by 10.140.109.246 with SMTP id l109mr45294330qgf.72.1398172599144; Tue, 22 Apr 2014 06:16:39 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id s10si11973532qak.60.2014.04.22.06.16.38 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 22 Apr 2014 06:16:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) 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 1WcaXz-0006XE-7L; Tue, 22 Apr 2014 13:15:39 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WcaXk-0006G7-87 for xen-devel@lists.xenproject.org; Tue, 22 Apr 2014 13:15:24 +0000 Received: from [85.158.137.68:50585] by server-8.bemta-3.messagelabs.com id B4/2C-21547-B6B66535; Tue, 22 Apr 2014 13:15:23 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-7.tower-31.messagelabs.com!1398172522!8189694!1 X-Originating-IP: [74.125.83.45] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22187 invoked from network); 22 Apr 2014 13:15:22 -0000 Received: from mail-ee0-f45.google.com (HELO mail-ee0-f45.google.com) (74.125.83.45) by server-7.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 22 Apr 2014 13:15:22 -0000 Received: by mail-ee0-f45.google.com with SMTP id d17so4642275eek.4 for ; Tue, 22 Apr 2014 06:15:22 -0700 (PDT) X-Received: by 10.14.218.193 with SMTP id k41mr55576419eep.16.1398172522211; Tue, 22 Apr 2014 06:15:22 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id 45sm112969867eeh.9.2014.04.22.06.15.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Apr 2014 06:15:20 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 22 Apr 2014 14:14:33 +0100 Message-Id: <1398172475-27873-20-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398172475-27873-1-git-send-email-julien.grall@linaro.org> References: <1398172475-27873-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 v4 19/21] 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=neutral (google.com: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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. Signed-off-by: Julien Grall --- 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 362bc8d..998db1d 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; }