From: Julien Grall <julien.grall@linaro.org>
To: xen-devel@lists.xenproject.org
Cc: stefano.stabellini@citrix.com,
Julien Grall <julien.grall@linaro.org>,
tim@xen.org, ian.campbell@citrix.com
Subject: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Date: Thu, 15 May 2014 15:16:23 +0100 [thread overview]
Message-ID: <1400163385-19863-3-git-send-email-julien.grall@linaro.org> (raw)
In-Reply-To: <1400163385-19863-1-git-send-email-julien.grall@linaro.org>
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 <julien.grall@linaro.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
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;
}
--
1.7.10.4
next prev parent reply other threads:[~2014-05-15 14:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-15 14:16 [PATCH v7 0/4] IOMMU support for ARM Julien Grall
2014-05-15 14:16 ` [PATCH v7 1/4] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk Julien Grall
2014-05-15 15:20 ` Ian Campbell
2014-05-15 15:24 ` Julien Grall
2014-05-15 15:51 ` Ian Campbell
2014-05-15 16:05 ` Jan Beulich
2014-05-15 16:04 ` Jan Beulich
2014-05-15 17:06 ` Julien Grall
2014-05-16 10:00 ` Ian Campbell
2014-05-15 14:16 ` Julien Grall [this message]
2014-05-17 18:12 ` [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m Julien Grall
2014-05-19 9:45 ` Ian Campbell
2014-05-19 14:20 ` Julien Grall
2014-05-20 7:30 ` Roger Pau Monné
2014-05-20 8:51 ` Ian Campbell
2014-05-20 11:19 ` Julien Grall
2014-05-20 11:25 ` Ian Campbell
2014-05-20 11:53 ` Julien Grall
2014-05-15 14:16 ` [PATCH v7 3/4] xen: iommu: Define PAGE_{SHIFT, SIZE, ALIGN, MASK)_64K Julien Grall
2014-05-15 14:16 ` [PATCH v7 4/4] drivers/passthrough: arm: Add support for SMMU drivers Julien Grall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400163385-19863-3-git-send-email-julien.grall@linaro.org \
--to=julien.grall@linaro.org \
--cc=ian.campbell@citrix.com \
--cc=stefano.stabellini@citrix.com \
--cc=tim@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).