From patchwork Thu May 15 12:56:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 30254 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3B9C7202E6 for ; Thu, 15 May 2014 12:59:00 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id rl12sf5226041iec.2 for ; Thu, 15 May 2014 05:58:59 -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=B9Fgc1zWOJwiBgGq42RXPuh5F7hGPI26jv8wY+rviYzRrj51+F97GgXbV+gW2e+64W txYEcsFdDBlA7Y1jVDykUEs6uv9YfvN3mhrmxcaQ1aoIvkg+pZeMuapbNKwP06ocU1Og kzXPLsOd5VNmHvkqx0gpmlRn/8gTxcg1L9+Sog+jXpeI5znrGhzARvGZJJ7IzgZy4Cb3 w0RYelZ1gZUdUYkQlkBxzy/32qjPfQOaIDDoAsqwMnHW0QCdhtMzOIHVW/PGdbnfqY8y SZAGLLM/sK0ykzz+AXhYMTFWtGwAIxwr2YKMEQgZL4IeVONXQNukB3GT5wBFvImDzMMN 0RnQ== X-Gm-Message-State: ALoCoQk9Sov8TtJJomjuumAj4JgWOCjMwuYECOEE9gm3m/Xug1tEevEErZ8w+gJ3u4C59sT5/Ij7 X-Received: by 10.182.104.200 with SMTP id gg8mr4955831obb.45.1400158739463; Thu, 15 May 2014 05:58:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.29.4 with SMTP id a4ls222555qga.45.gmail; Thu, 15 May 2014 05:58:59 -0700 (PDT) X-Received: by 10.52.104.72 with SMTP id gc8mr308769vdb.48.1400158739347; Thu, 15 May 2014 05:58:59 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id dx1si919766vcb.214.2014.05.15.05.58.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 May 2014 05:58:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.173 as permitted sender) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id pa12so1209335veb.18 for ; Thu, 15 May 2014 05:58:59 -0700 (PDT) X-Received: by 10.58.216.163 with SMTP id or3mr47366vec.80.1400158739164; Thu, 15 May 2014 05:58:59 -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 ib8csp320210vcb; Thu, 15 May 2014 05:58:58 -0700 (PDT) X-Received: by 10.52.229.197 with SMTP id ss5mr39417vdc.83.1400158738347; Thu, 15 May 2014 05:58:58 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ql8si928581veb.32.2014.05.15.05.58.57 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 15 May 2014 05:58:58 -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 1WkvDX-0004xJ-8Y; Thu, 15 May 2014 12:56:59 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WkvDV-0004wr-Kv for xen-devel@lists.xenproject.org; Thu, 15 May 2014 12:56:57 +0000 Received: from [193.109.254.147:3229] by server-7.bemta-14.messagelabs.com id 26/A2-17726-999B4735; Thu, 15 May 2014 12:56:57 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-14.tower-27.messagelabs.com!1400158616!5032674!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.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20905 invoked from network); 15 May 2014 12:56:56 -0000 Received: from mail-ee0-f45.google.com (HELO mail-ee0-f45.google.com) (74.125.83.45) by server-14.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 15 May 2014 12:56:56 -0000 Received: by mail-ee0-f45.google.com with SMTP id d49so623595eek.18 for ; Thu, 15 May 2014 05:56:56 -0700 (PDT) X-Received: by 10.15.34.197 with SMTP id e45mr2607135eev.112.1400158615936; Thu, 15 May 2014 05:56:55 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id a4sm12518554eep.12.2014.05.15.05.56.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 May 2014 05:56:55 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 15 May 2014 13:56:46 +0100 Message-Id: <1400158608-9617-3-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1400158608-9617-1-git-send-email-julien.grall@linaro.org> References: <1400158608-9617-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 v6 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.128.173 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; }