From patchwork Thu May 15 14:16:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 30261 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 3A0ED20446 for ; Thu, 15 May 2014 14:18:14 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf5675863pab.9 for ; Thu, 15 May 2014 07:18:13 -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=BILFnvg7Ugap3wfmDnbPKNmhsyAz604Yl4INF33CUTVa/89PCcDmz/ZyWnDpCsbkhl e1Z76sBvviohQuVtK+UMFpS1d20T2Oi1qm8taHyX4AjpcNBGY0IMqkFQgMapyddqVHny YT/XXquH/0nB4v7bDlS4HWqrbv9iSAsuCNp1Z8vx8uFHzb/6r1D2MENCM+Azg7pp8MAc 0PPOSLKcAsZm/ZdhzR/stHaR9B3aZKTk3TEha3+1pRRgfw2o61WV6GsfJALa3XkSbO7u cSP3IPR2Zr04h4S9+bMHDZfP4sMEZC7ObMu5n+gqLXwypT7SK5d1R21sIybeTZGdXzKe AxFA== X-Gm-Message-State: ALoCoQlPskzEAQkKZhjnQjWV3zTbZceVepAMoJq+PgyHZlFdzga4ghKCS8qIyGOsJaYUz2Xyymg7 X-Received: by 10.68.230.193 with SMTP id ta1mr5107356pbc.6.1400163493563; Thu, 15 May 2014 07:18:13 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.47.203 with SMTP id m69ls275298qga.84.gmail; Thu, 15 May 2014 07:18:13 -0700 (PDT) X-Received: by 10.52.248.41 with SMTP id yj9mr7432226vdc.22.1400163493457; Thu, 15 May 2014 07:18:13 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id ck5si960797vdd.127.2014.05.15.07.18.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 May 2014 07:18:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id lc6so4412281vcb.2 for ; Thu, 15 May 2014 07:18:13 -0700 (PDT) X-Received: by 10.52.11.230 with SMTP id t6mr7336733vdb.27.1400163493366; Thu, 15 May 2014 07:18:13 -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 ib8csp326344vcb; Thu, 15 May 2014 07:18:13 -0700 (PDT) X-Received: by 10.220.183.4 with SMTP id ce4mr487318vcb.54.1400163492685; Thu, 15 May 2014 07:18:12 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id b5si963581vej.137.2014.05.15.07.18.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 15 May 2014 07:18:12 -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 1WkwSY-0002gA-JZ; Thu, 15 May 2014 14:16:34 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WkwSX-0002fx-AK for xen-devel@lists.xenproject.org; Thu, 15 May 2014 14:16:33 +0000 Received: from [193.109.254.147:54351] by server-12.bemta-14.messagelabs.com id 91/BB-27473-04CC4735; Thu, 15 May 2014 14:16:32 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-12.tower-27.messagelabs.com!1400163391!5069793!1 X-Originating-IP: [74.125.83.41] 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 17898 invoked from network); 15 May 2014 14:16:31 -0000 Received: from mail-ee0-f41.google.com (HELO mail-ee0-f41.google.com) (74.125.83.41) by server-12.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 15 May 2014 14:16:31 -0000 Received: by mail-ee0-f41.google.com with SMTP id t10so730113eei.28 for ; Thu, 15 May 2014 07:16:31 -0700 (PDT) X-Received: by 10.15.44.3 with SMTP id y3mr14719224eev.58.1400163391452; Thu, 15 May 2014 07:16:31 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id x45sm12956780eee.37.2014.05.15.07.16.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 May 2014 07:16:30 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 15 May 2014 15:16:23 +0100 Message-Id: <1400163385-19863-3-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1400163385-19863-1-git-send-email-julien.grall@linaro.org> References: <1400163385-19863-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 v7 2/4] 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.220.171 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; }